Can maven treat WEB-INF\lib the way eclipse (and m2e) does?

↘锁芯ラ 提交于 2019-12-11 18:56:54

问题


I have a servlet/jsp web project which runs fine on eclipse and is exported as war fine (once I clean it that is). I mavenized the project deleting all of the dependencies from the WEB-INF\lib folder except a homebrew jar (the output of another project in the workspace). When I run the package maven goal I get messages for missing classes from this jar:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
#..... NOTICE THIS COMES FROM A CUSTOM JAR
[ERROR] /C:/path/DataServlet.java:[3,30] package xxx.java.helpers does not exist

Now this has been asked before and the most rigorous solution appears to be to create a local repo: Can I add jars to maven 2 build classpath without installing them? (NB: I am at maven 3).

I would like to avoid this - so is there any way maven will just stuff this jar to WEB-INF\lib in the war ?

Solutions that use some maven plugin to cp the contents of the WEB-INF\lib in the war are welcome - although I just have this feeling that there should be a solution that takes into account the "special" nature of this folder.

Observations:

  • Alt+F5 removes this line:

    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    

    which corresponds to the "Web App libraries" in the Java Build Path. So not only maven refuses to take into account the WEB-INF\lib - it also breaks the build path of eclipse completely.

Related:

  • Maven: How to include jars in Eclipse, which are not available in repository?
  • Uses the maven eclipse plugin : update my classpath with an Eclipse User Library via the maven eclipse plugin - not compatible with m2e
  • How does the m2e eclipse plugin interact with eclipse? - apparently m2e checks the pom then calls the eclipse builders (hence the .classpath is read)
  • Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server
  • Deploying a Maven project with dependencies to Tomcat or Jboss running within Eclipse

回答1:


Did you add this jar from WEB-INF\lib as a dependency like this:

<dependency>
  <groupId>someGroupId</groupId>
  <artifactId>someArtifactId</artifactId>
  <version>1.0.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/homebrew jar</systemPath>
</dependency>


来源:https://stackoverflow.com/questions/24287093/can-maven-treat-web-inf-lib-the-way-eclipse-and-m2e-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!