开发者

How do you ensure a Utility Projects library dependency gets packaged in the final EAR in Eclipse Galileo?

I have a 'Utilty Project', and an 'EAR Project' that includes that 'Utility Project'. All the classes from the 'Utility Project' end up being packaged as a JAR and placed within the 'lib' directory of the exported EAR, for example:

  EAR.ear
    META-INF
      MANIFEST.MF
    lib
      utility.jar (which expands to):
        META-INF
          MANIFEST.MF
        com
          acme
            Foo.class
            Bar.class

However, the 'Utility Project' relies on a library (freemarker.jar) that has been added to the build path using 'Properties > Java Build Path > Libraries'. All I want to do is to get freemarker.jar added to the EAR as follows:

  EAR.ear
    META-INF
      MANIFEST.MF
    lib
      **freemarker.jar**
      utility.jar (which expands to):
        META-INF
          MANIFEST.MF
        com
          acme
            Foo.class
            Bar.class

By searching around within Eclipse I've found 4 potential avenues for achieving this, none of which have worked. If someone can just cut to the chase and tell me what I should actually do, that would be great. But just in case, I'll iterate them here:

From the 'Utility Project' Properties:

  1. If I click 'Java Build Path > Order and Export' and select 'freemarker.jar' for export, the jar does not end up in the EAR file at all.
  2. If I click 'Java EE Module Dependencies' and select the 'freemarker.jar' library as a dependency, it says:

This JAR is a bundled library of an EAR project and is supposed to be packed in the EAR's library directory. It conflicts with the manifest class path dependency you are trying to create. If you create this dependency, the JAR will be packed in the root (not library) directory of the EAR. Are you sure you want to proceed?

From the 'EAR Project' Properties:

  1. If I click 'Java EE Module Dependencies > Add JARs...' 开发者_JAVA百科and navigate to the 'freemarker.jar', and make it a dependency, it gets added to the root of the EAR: /freemarker.jar
  2. If I do the same as above, but check the 'In Lib Dir' checkbox, it gets added into the lib folder, but contained within another lib folder: /lib/lib/freemarker.jar

Thanks.


I've managed to solve this problem. In the Problems window I was getting the following warning:

Classpath entry /utility-project/lib/freemarker.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.

What I tried, at a whim, was to use the Ctrl-1 key combination I've been using to get quick fix solutions for my source code. It turns out this also provides quick-fix solutions for for the given errors and warnings. I chose the first of the two options:

Mark the associated raw classpath entry as a publish/export dependency.

and my problem disappeared!

Bizarrely, all this seems to have done is to cause the 'freemarker.jar' lib to be selected in the 'Java EE Module Dependencies' properties dialog, which I was doing myself anyway. This may be an Eclispe bug!


@MonoThreaded: After using the quick fix > Mark the associated raw classpath entry as published/export dependency, if you right-click on the project > properties > depolyment assembly you will notice that eclipse has added a new entry, something like source: /freemaker.jar, deploy path: ../lib. You can do that too, by selecting Add > Java Build Path Entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜