【发布时间】:2020-06-16 00:56:28
【问题描述】:
我有一个项目,其中的包将被重新定位(阴影 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只能下载阴影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? .
打开项目的属性。在 Tap Maven 下,取消勾选“Resolve dependencies from Workspace projects”
【问题讨论】:
标签: java eclipse maven dependencies uberjar