我有一个项目,其中的包将被重新定位(阴影 jar)
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>artifact-child</artifactId>
<name>artifact-child</name>
<parent>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>${revision}</version>
</parent>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<!-- <shadedArtifactAttached>true</shadedArtifactAttached> -->
<relocations>
<reloaction>
<pattern>example</pattern>
<shadedPattern>${super-package}.example</shadedPattern>
</reloaction>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我有第二个项目,它需要在运行时使用阴影 jar。
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testversion</groupId>
<artifactId>testv</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testv</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>artifact-child</artifactId>
<version>0.0.1</version>
<classifier>shaded</classifier>
</dependency>
</dependencies>
</project>
我的问题:
Eclipse在他的工作区中找到另一个项目并直接使用源代码。
例如:我必须编写 import example.myclass
而不是 import org.example.myclass
。
在某些情况下,这可能是一个问题。是否可以说,什么maven或eclipse应该使用“shaded jar”而不是原始源代码?
我必须创建一个在线存储库,这样maven只能下载shaded jar吗?
我发现了另外两篇 stackoverflow 帖子(没有结果):
Maven Eclipse multi-module shaded dependency
How to install shaded jar instead of the original jar
已解决:
我的错误:
1.父版本必须直接声明,而不是通过属性
2.忘记运行“Maven Install”
解决方案:
Maven 运行没有错误,但 Eclipse 使用打开的项目而不是阴影 jar。
在这里找到解决方案:How can I download a single raw file from a private github repo using the command line? .
打开项目的属性。在点击 Maven 下,删除“解决工作空间项目的依赖关系”的勾选
最佳答案
如果阴影 jar 是您的依赖项,您只需引用阴影 jar 中定义的类/包即可。
如果 Eclipse 显示错误,则 Eclipse 是错误的(这种情况经常发生)。首先,尝试使用 clean verify
之类的东西构建您的项目。然后您会看到您是否真的有错误(或者这些错误是否是 Eclipse 编造的)。
如果 Eclipse 错误困扰您,请尝试 ALT+F5。
关于java - Maven (eclipse) 使用阴影 jar 代替原始 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60510702/