【问题标题】:Maven Not Copying Dependencies to WEB-INF/lib in EclipseMaven 未在 Eclipse 中将依赖项复制到 WEB-INF/lib
【发布时间】:2015-02-28 09:41:03
【问题描述】:

我意识到在 StackOverflow 上已多次提出非常相似或相同的问题,但大多数(如果不是全部)似乎最终都有不同的解决方案。

我已经尝试了从此处和其他地方发布的类似问题中找到的几乎所有内容,但我仍然无法让 Maven 将依赖项 JAR 放入 WEB-INF/lib 中。

最奇怪的是,每次我运行 Maven -> Update Project 时,Maven 似乎都将类输出文件夹重新配置为 /target/classes,而不是 Google Web 应用插件所需的 /war/WEB-INF/classes。

在构建路径中的 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 终端命令吗?除了手动管理所有依赖项之外,我真的不知所措(请...不)。

【问题讨论】:

  • 您似乎没有按照Importing a Maven Project 的说明进行操作,因为您尚未指定 appengine-maven-plugin 配置。
  • 我一定错过了。我在 下添加了它,但它并没有解决问题。由于某种原因,Maven -> 更新项目也仍然恢复使用 /target/classes。
  • 您的项目可能未正确设置为 maven。检查您的 Web 项目 - Properties &gt; Deployment Assembly 中是否将 Maven 依赖项设置为部署到 WEB-INF/lib。

标签: java google-app-engine maven jakarta-ee classpath


【解决方案1】:
<build>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>
</build>

将其添加到您的 pom.xml 中。每次执行 Maven 更新时,它都会停止更改输出目录。

【讨论】:

  • 这个问题现在有点老了,但我很确定这是正确的解决方案,iirc。
猜你喜欢
  • 2012-09-10
  • 1970-01-01
  • 2012-04-22
  • 2011-03-26
  • 2011-08-30
  • 1970-01-01
  • 2011-04-23
  • 2010-09-10
  • 2010-09-10
相关资源
最近更新 更多