2011-02-15 178 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