我一直在研究最終創建可執行jar文件的Java Maven項目。起初,我沒有問題,但後來我決定我想將依賴關係複製到jar中。如何創建一個具有依賴性的jar作爲主構建工件,稍後由assembly插件使用?
我發現下面的(非常有用)棧溢出問題,隨後在回答中提供的說明(代我自己的主類和目標版本):Problem building executable jar with maven
這奇妙的工作,但我結束了兩個jar文件(ldap-daemon-0.0.1-SNAPSHOT.jar和ldap-daemon-0.0.1-SNAPSHOT-jar-with-dependencies.jar)。我可以肯定這一點,但據我所知,我實際上無法在以後使用maven-dependency-plugin的複製功能獲得具有依賴項的jar副本。
所以,我想知道的是如何完成下列操作之一:
- 有我的主構建神器,LDAP守護-0.0.1-SNAPSHOT.jar,包括它的依賴
- 使用maven-dependency-plugin複製第二個構建工件(ldap-daemon-0.0.1-SNAPSHOT-jar-with-dependencies.jar)。
下面是LDAP守護我的插件配置(包裝配置是「罐子」):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.acuitus.ldapd.LDAPDaemonImp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
,這裏是我的插件配置試圖將產生的JAR複製到一個文件夾中的下游項目:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.acuitus</groupId>
<artifactId>ldap-daemon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes/www-export</outputDirectory>
<destFileName>ldap-daemon.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
任何援助是非常感謝。謝謝你的時間!
它是一種依賴,而我執行MVN安裝,但我可以在下游項目得到的是LDAP守護-0.0.1-SNAPSHOT.jar,不是LDAP守護-0.0.1-SNAPSHOT-JAR-與-dependencies.jar。在上面的第二個插件配置中,我無法找到任何成功的值。我不覺得我需要使用陰影插件,因爲我創建的jar是正確的,並且在正確的目錄中,但我根本不知道如何在下游項目中引用它。我誤解了陰影插件的好處嗎?感謝您花時間回答。非常感激! – 2013-05-08 22:42:03
嗨。對不起昨天有點困惑,並沒有得到你的要求。我已經更正了上面的答案,並希望這是您正在尋找的內容。 – mszalbach 2013-05-09 08:49:21
完成這項工作:)謝謝!我們最近更改了構建系統,而且我仍然在加快Maven的速度。我感謝您的幫助! – 2013-05-09 18:57:34