开发者

Eclipse + Maven - Missing JAR in WAR export

The project (a standard WAR with Spring) builds and packages fine from the command line via mvn package. I have also ran mvn eclipse:eclipse to configure the Eclipse project. Now here is where the oddness starts.

The project has no errors in Eclipse and all of the dependencies from the pom.xml are correctly referenced in the .classpath file and in the build-path of the project in Eclipse. However, if I try to run the project on a server or export the project as a WAR it leaves out one jar, a custom built in-house JAR.

The pom.xml entry for the depency of the missing jar...

<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>lib_ourlib</artifactId>
    <version>1.0-SNAPSHOT</version>
</depend开发者_Go百科ency>

The project's .classpath file showing that it looks just like any other entry...

<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/mycompany/lib_ourlib/1.0-SNAPSHOT/lib_ourlib-1.0-SNAPSHOT.jar"/>
  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1_2_6/log4j-1_2_6.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.0.5.RELEASE/spring-aop-3.0.5.RELEASE.jar"/>
  <!-- a lot of spring jars -->
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

Why would Eclipse pick up the Spring jars but not ours? Is there some restriction to using a SNAPSHOT vs a RELEASE?


Ok, after a few more hours I figured it out. Adding JARs to the build-path is not enough. You must also add them as J2EE dependencies under the project's properties in Eclipse.


On the other hand you do something wrong. You do not need maven-eclipse-plugin at all. You should use m2eclipse and m2extras as well. Quite disturbing that this two is not bundled into one update site. So install WTP extension from the m2extras, and you will get eclipse WAR configuration based on your POM at saving it. It is a golden rule according to my experience with maven+WTP, that your should never touch dependencies in eclipse, just let m2 to generate it for you. The only case, when you need to adjust it is the case of project facets like JPA and so on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜