2011-02-15 218 views
2

我正在做一個maven項目。編譯和運行我的項目時,一切都很順利,但每當我創建jar文件時,web/lib /中的外部jar文件都不能複製到jar文件中。爲什麼會發生?我可以將所有文件插入jar文件嗎?將jar庫添加到jar文件中

回答

0

是我找到的解決方案。

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.2</version> 
    <configuration> 
  
        <finalName>HelloWorld</finalName> 
  
        <archive> 
            <manifest> 
                <addClasspath>true</addClasspath> 
                <mainClass>com.gui.launcher.LauncherMain</mainClass> 
            </manifest> 
        </archive> 
  
        <descriptorRefs> 
            <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
    </configuration> 
  
    <executions> 
        <execution> 
            <id>make-assembly</id> 
            <!-- this is used for inheritance merges --> 
            <phase>package</phase> 
            <!-- append to the packaging phase. --> 
            <goals> 
                <goal>single</goal> 
                <!-- goals == mojos --> 
            </goals> 
        </execution> 
    </executions> 
</plugin> 
1

您需要使用是這樣的:

</project> 
... 
<build> 
     ... 
     <plugins> 
      <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <archive> 
       <manifest> <!-- requires for executable Jar --> 
        <mainClass>org.my.main.MainClass</mainClass> 
       </manifest> 
       </archive> 
       <descriptorRefs> 
       <descriptorRef>jar-with-dependencies</descriptorRef> <!-- final Jar will have this text appended --> 
       </descriptorRefs> 
      </configuration> 
     <executions> 
      <execution> 
      <id>make-assembly</id> <!-- this is used for inheritance merges --> 
      <phase>package</phase> <!-- append to the packaging phase. --> 
      <goals> 
       <goal>single</goal> <!-- goals == mojos --> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     .... 
     </plugins> 
    </build> 
</project> 
+0

我已經使用過這個插件。我在我的項目中使用Symmetricds jar文件,但在jar文件中看不到這些jar文件。在web/lib目錄中對稱jar文件。 – olyanren 2011-02-15 08:33:40