gpt4 book ai didi

java - Eclipse 中的 Maven 依赖错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:18:33 24 4
gpt4 key购买 nike

我有一件 war 文物,我需要使用 jar 里的一些类。我无法将这些类移动到另一个项目,然后我使用以下配置将我的 webapp 中包含的类和资源部署为“附加” Artifact :

<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>

这将导致部署两个 Artifact :mywebapp-1.0-SNAPSHOT.war 和 mywebapp-1.0-SNAPSHOT-classes.jar。

要使用这些类,我按如下方式引用 Artifact :

    <dependency>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<version>${project.version}</version>
<classifier>classes</classifier>
</dependency>

当我从 Jenkins 编译时一切正常,但是当我从 Eclipse 本地运行测试时找不到引用类。 (java.lang.NoClassDefFoundError)

我认为这可能是 maven eclipse 插件中的错误,有人知道会发生什么吗?

最佳答案

解决方法在 http://wiki.eclipse.org/M2E-WTP_FAQ 中有描述:

A workaround exists though, we need to change the dependency whether the project is built in Eclipse or not. In your dependent project, you can configure the following :

<dependencies>
...
<dependency>
<groupId>com.company</groupId>
<artifactId>mywebapp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>${webClassifier}</classifier>
</dependency>
...
</dependencies>
...
<properties>
...
<webClassifier>classes</webClassifier>
</properties>
...
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<webClassifier></webClassifier>
</properties>
</profile>
</profiles>

The m2e profile is automatically activated when the project is built with m2e, ignored in other circumstances. In that case only, the dependent project will use an empty classifier to reference the web project, which will be added to the classpath as expected.

关于java - Eclipse 中的 Maven 依赖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10417637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com