【问题标题】:Maven (eclipse) use shaded jar instead of original jarMaven (eclipse) 使用阴影 jar 代替原来的 jar
【发布时间】: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


    【解决方案1】:

    如果阴影 jar 是您的依赖项,您只需引用在阴影 jar 中定义的类/包。

    如果 Eclipse 显示错误,则 Eclipse 是错误的(通常是这种情况)。首先,尝试使用clean verify 之类的内容构建您的项目。然后你看看你是否真的有错误(或者如果 Eclipse 编造了这些错误)。

    如果 Eclipse 错误困扰您,请尝试 ALT+F5。

    【讨论】:

    • 好的。我需要 1 小时来制作 eclipse 来构建第二个项目 (sp) xD。我的第一个问题是,我在父版本“${revision}”下的第一个项目(fp)中编写,而不是确切的版本。第二个问题是我忘记在 fp 上运行 Maven 安装。但是我怎么能说,Eclipse 使用带阴影的 jar 而不会显示错误的错误呢?
    猜你喜欢
    • 2015-10-26
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2018-10-22
    • 2018-05-03
    • 2019-03-27
    • 2017-12-16
    • 1970-01-01
    相关资源
    最近更新 更多