maven embed dependency artifact code in jar

前端 未结 1 1681
我在风中等你
我在风中等你 2020-12-20 09:48

I have a multi-module maven project. I have a main \"base-code\" module which creates a jar of all the compiled source code in my project.

I have another module,

相关标签:
1条回答
  • 2020-12-20 10:19

    What you are looking for is probably uber-jar: a single jar file with all embedded jar dependencies, the newly version of maven-assembly-plugin support this as one of the 4 pre-defined descriptor, check out here.

    Try using maven-assembly-plugin replace your maven-jar-plugin like this:

    <!-- Create single executable jar with all dependencies unpacked and embedded -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.myproject.Main</mainClass>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
            </manifest>
          </archive>
          <descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals><goal>single</goal></goals>
          </execution>
        </executions>
      </plugin>
    

    Alternatively, you can also use maven-shade-plugin to do this.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题