In java EE, which jars should I put in the library dir?

后端 未结 3 492
走了就别回头了
走了就别回头了 2021-01-04 09:28

I have a Java EE project. The project is built using maven into an .ear archive. There is a library jar containing a JPA 2 persistence unit, which is located in the library

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 10:03

    Are there any guide lines for what should be put in the library directory, and is my solution generally acceptable?

    You've pretty much nailed it, JARs that should be available to all the EAR modules should go here.

    Why aren't the libraries in the root of the ear available to the jars in the lib directory?

    It usually works the other way round, the JARs in the lib folder are available to the ones in the root. However, I believe you can achieve this by using :

    
        org.nisse
        hue
        true
    
    

    Why doesn't maven figure this out automatically?

    I assume you mean that maven doesn't automatically place all transitive dependencies in lib? I believe it should do, and does - can you show the relevant portion of your POM perhaps?

    Edit: Your EAR module should only reference the EJB JARs and WARs as dependencies. Any transitive dependencies should be included in the EAR automatically, at top level by default - this can be overridden with the tag in the ear-plugin :

    org.apache.maven.plugins
    maven-ear-plugin
    2.7
    
        lib
        
            
                true
            
        
        
           ... etc.
    

    Also the / section should ensure that the MANIFEST classpath is set correctly. Perhaps this is exactly what you're missing?

    Cheers,

提交回复
热议问题