Unable to get unpack-dependencies to run before jar:jar,

落花浮王杯 提交于 2020-01-23 18:21:09

问题


I cannot get maven-dependency-plugin/unpack-dependencies to run before maven-jar-plugin/jar when running mvn clean install from the command line.

Every time, I see it running jar:jar before the unpack stuff runs, I saw in my googling some talk of adding a pre-package phase to the maven lifecycle, doesn't seem to be working thought.

Basically I want to create a single jar file containing all necessary classes (all 2600 of them). This jar gets a Manifest which enables it to be run in the manner of:

java -jar blah.jar 

If I ever get it to work...

And here's the xml snippet...

      <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>

回答1:


In your original question, replace the phase with the following phase.

<phase>prepare-package</phase>

this will cause the jars to be extracted first. For your problem, the shade solution is better, but I will still post this here as a reference for other with similar problems where shade does not help.

The output path is set to make sure that jar's contents end up in dir that the jar:jar goal packages (target/classes).

Full plugin execution xml snippet:

        <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>



回答2:


I had similiar issue with single jar creation. My solutions incorporates standard maven-dependency plugin with unpack goal (unpacks all dependencies during compile process and move it into custom outputDirectory. The secret is, JAR plugin takes all from target/classes directory and packs as a one JAR.

That's why I defined custom outputDirectory. Have a look at the code below:

  <build>
<plugins>
  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <finalName>${project.artifactId}</finalName>
      <archive>
        <manifest>
          <mainClass>pl.company.client.Uploader</mainClass>
        </manifest>
      </archive>
    </configuration>
    <version>2.3.1</version>
  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.4</source>
      <target>1.4</target>
    </configuration>
    <version>2.3.2</version>
  </plugin>

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack-dependencies</id>
        <phase>compile</phase>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/classes</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

<resources>
  <resource>
    <directory>src/main/resources</directory>
  </resource>
</resources>




回答3:


You may run it by identifying the goal sequentially as

"mvn clean dependency:unpack jar:jar install"

I hope this may help you to achieve the requirement

Regards,

Charlee Ch.



来源:https://stackoverflow.com/questions/6551374/unable-to-get-unpack-dependencies-to-run-before-jarjar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!