2013-07-16 51 views
11

Tôi đọc rất nhiều giải pháp để xây dựng jar thực thi với phụ thuộc (plugin maven shade, plugin phụ thuộc maven, plugin lắp ráp maven) và tất cả các plugin này giải nén phụ thuộc lọ và đóng gói lại chúng trong lọ thực thi. Plugin duy nhất đóng gói các gói phụ thuộc được giải nén trong jar thực thi là một plugin jar nhưng plugin này thêm mã runner của nó vào jar thực thi.Maven plugin để tạo jar thực thi với các phụ thuộc không được giải nén (jar với lọ)

Có giải pháp nào để tạo jar như thế này:

├─executable.jar 
├──lib/ 
├───dependency1.jar 
├───dependency2.jar 
. 
. 
. 

và rằng giải pháp để làm việc.

+0

Bạn có thể sẽ cần một tùy chỉnh đẳng cấp nạp để nạp các lớp được đóng gói trong lọ bên trong một kho lưu trữ. Bạn đã xem [jar] (http://one-jar.sourceforge.net/) chưa? –

Trả lời

0
<plugins> 
      <plugin> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <version>2.9</version> 
       <configuration> 
        <additionalProjectnatures> 
         <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
        </additionalProjectnatures> 
        <additionalBuildcommands> 
         <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
        </additionalBuildcommands> 
        <downloadSources>true</downloadSources> 
        <downloadJavadocs>true</downloadJavadocs> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArgument>-Xlint:all</compilerArgument> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <configuration> 
        <mainClass>org.test.int1.Main</mainClass> 
       </configuration> 
      </plugin> 
     </plugins> 
+0

bạn có thể thêm yhis vào tệp pom.xml của mình. sau này bạn có thể nhận được jar thực thi – Ritesh

1

Cách phổ biến nhất là sử dụng plugin lắp ráp mà sẽ cho phép bạn cấu hình bao bì một cách bạn cần

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <archive> 
       <manifest> 
        <mainClass>com.somewhere.Main</mainClass> 
       </manifest> 
     </archive> 
     <descriptorRefs> 
       <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
    </configuration> 
    <executions> 
      <execution> 
       <id>make-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
     </execution> 
    </executions> 
</plugin> 

Ngoài ra bạn có thể chỉ mô tả lắp ráp cho cấu hình

<configuration> 
    <appendAssemblyId>false</appendAssemblyId> 
    <descriptors> 
     <descriptor>src/main/assembly/assembly.xml</descriptor> 
    </descriptors> 
</configuration> 

Và assembly.xml chính nó

<assembly> 
    <id>assembly</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets> 
     <fileSet> 
      <directory>${project.build.outputDirectory}</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
    </fileSets> 
</assembly> 

mô tả hội cũng có thể chứa phần phụ thuộc:

<!-- lib --> 
<dependencySets> 
    <dependencySet> 
     <outputDirectory>lib</outputDirectory> 
    </dependencySet> 
</dependencySets> 

Theo như tôi hiểu bạn đang tìm kiếm người cuối cùng. Vì nó chỉ bao gồm các tệp jar vào assembly mà không có bất kỳ sửa đổi nào. Vì vậy, giải pháp cuối cùng sẽ như thế nào:

<assembly> 
    <id>assembly</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <!-- lib --> 
    <dependencySets> 
     <dependencySet> 
      <outputDirectory>lib</outputDirectory> 
     </dependencySet> 
    </dependencySets> 
</assembly> 

và pom phần:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <appendAssemblyId>false</appendAssemblyId> 
     <descriptors> 
      <descriptor>src/main/assembly/assembly.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <executions> 
      <execution> 
       <id>make-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
     </execution> 
    </executions> 
</plugin> 
Các vấn đề liên quan