我意识到 StackOverflow 上已经多次提出非常相似或相同的问题,但大多数(如果不是全部)似乎最终都有不同的解决方案。
我已经尝试了从此处和其他地方发布的类似问题中找到的几乎所有内容,但我仍然无法让 Maven 将依赖项 JAR 放入 WEB-INF/lib 中。
最奇怪的是,每次我运行 Maven -> 更新项目时,Maven 似乎都会将类输出文件夹重新配置为 /target/classes
而不是 /war/WEB-INF/classes
这是 Google 网络应用插件所需的。
构建路径中的 Maven 依赖项下的所有内容都正确显示,但 WEB-INF/lib 中没有显示任何内容,因此应用程序在运行时失败并出现 ClassNotFoundExceptions。
这是 pom.xml 的相关部分:
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<webXml>war/WEB-INF/web.xml</webXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>RELEASE</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
我需要在 M2E 设置中配置什么吗?我需要使用 Maven 终端命令吗?除了手动管理所有依赖项(请...不)之外,我真的不知道该怎么做。
最佳答案
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
</build>
将其添加到您的 pom.xml 中。每次执行 Maven 更新时,它将停止更改输出目录。
关于java - Maven 未将依赖项复制到 Eclipse 中的 WEB-INF/lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27735697/