无法在jar:jar之前运行unpack依赖项,

Bry*_*unt 1 dependencies execution maven

从命令行运行mvn clean install时,我无法在maven-jar-plugin/jar之前运行maven-dependency-plugin/unpack-dependencies.

每次,我看到它在运行jar包之前运行jar:jar,我在google搜索中看到一些关于在maven生命周期中添加预包阶段的讨论,似乎没有工作思路.

基本上我想创建一个包含所有必要类(所有2600个)的jar文件.这个jar获得了一个Manifest,使它能够以下列方式运行:

java -jar blah.jar 
Run Code Online (Sandbox Code Playgroud)

如果我能让它上班......

这是xml片段......

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
         <version>2.2</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                </execution>
            </executions>
          </plugin>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>archivedb.Read</mainClass>
                    </manifest>
                </archive>
            </configuration>
          </plugin>
Run Code Online (Sandbox Code Playgroud)

小智 7

在您的原始问题中,将阶段替换为以下阶段.

<phase>prepare-package</phase>

这将导致首先提取罐子.对于你的问题,阴影解决方案是更好的,但我仍然会在这里发布此作为其他类似问题的参考,其中阴影没有帮助.

输出路径设置为确保jar的内容最终以jar:jar目标包(目标/类)的dir结尾.

完整的插件执行xml片段:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <includes>**/*.class</includes>
                        <excludes>**/*.properties</excludes>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>

                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)