2010-08-06 53 views
5

我是從Ant的角度來的,所以請原諒我。我意識到這裏已經有很多關於如何設置依賴的問題,但是他們中沒有一個似乎告訴我們如何去做需要做的事情。如何將依賴關係複製到gae war/WEB-INF/lib

問題1: 目前,在使用maven-戰爭的插件,當我運行mvn戰相結合:戰爭,它會創建目標文件夾中的一個war文件夾。但是,我希望將所有依賴項的jar複製到由google eclipse plugin(gae enabled,gwt disabled)設置的war/WEB-INF/lib中,而不會覆蓋Google eclipse插件放置在那裏的jar。

我不想設置戰爭文件或戰爭目錄。我只需要將所有非gae jar文件複製/合併到gae jar文件中,這樣當項目作爲gae web應用程序運行時,Eclipse不會抱怨ClassNotFoundException。

問題2: 在Eclipse中使用Ant時,我可以在Eclipse中運行Ant目標。

現在,我必須從shell窗口執行mvn命令(這對於Eclipse會話的存在是相互忽略的)。看起來,只要我更新依賴關係,就會自動完成的唯一事情。

有沒有一種方法,或任何Eclipse的插件,可以讓我在Eclipse中運行mvn目標?

附加信息

mvn dependency:copy-dependencies在複製一直持續到target/dependency目錄,有以下幾點:

<plugin> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>copy-dependencies</id> 
     <phase>process-resources</phase> 
     <goals> 
      <goal>copy-dependencies</goal> 
     </goals> 
     <configuration> 
      <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory> 
      <overWriteReleases>false</overWriteReleases> 
      <overWriteSnapshots>false</overWriteSnapshots> 
      <overWriteIfNewer>true</overWriteIfNewer> 
      <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

我甚至試圖改變以絕對路徑

<outputDirectory> 
    /home/geek/eclipse/workspace/Demo-autoshoppe/holycow 
</outputDirectory> 

但holycow目錄仍然是空的,mvn仍然堅持複製到target/dependency目錄。我目前的解決方案是將target/dependency軟鏈接爲war/WEB-INF/lib,這是一個非常非常糟糕的kludge。爲什麼maven對outputDirectory規範不敏感?我正在使用Ubuntu的maven 2.2。

+0

請注意,m2e - Eclipse Maven插件 - 在Eclipse 3.8中變得更好,更好。 – 2012-10-11 14:23:42

回答

7

我有你的真實答案,我的男人。

使用「default-cli」執行ID。確保你使用的是Maven 2.2+。這個exec-id適用於mojo的命令行執行。

<build> 
    <pluginManagement> 
     <plugins> 
     <!-- Copy dependencies to war/WEB-INF/lib for GAE proj compliance. --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
      <execution> 
       <id>default-cli</id> 
       <goals> 
       <goal>copy-dependencies</goal> 
       </goals> 
       <configuration> 
       <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory> 
       <overWriteReleases>false</overWriteReleases> 
       <overWriteSnapshots>false</overWriteSnapshots> 
       <overWriteIfNewer>true</overWriteIfNewer> 
       <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds> 
       </configuration> 
      </execution> 
      </executions> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 

乾杯。

+0

感謝兄弟......這一個如此作品......花了一天的時間來解決這個問題 – 2011-05-21 13:36:14

+0

謝謝!如果僅複製活動的依賴關係而不是已過濾的依賴項(相同的工件,如果是不同的版本) – ZiglioUK 2012-09-23 11:29:34

2

一位員工通過電子郵件發送給我這個有效的答案。通過觸發 mvn buildmvn package 但不是直接通過mvn dependency:copy-dependencies

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>copy-dependencies</id> 
     <phase>package</phase> 
     <goals> 
      <goal>copy-dependencies</goal> 
     </goals> 
     <configuration> 
      <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory> 
      <overWriteReleases>false</overWriteReleases> 
      <overWriteSnapshots>false</overWriteSnapshots> 
      <overWriteIfNewer>true</overWriteIfNewer> 
      <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
+0

這仍然固執地將jar文件複製到目標/依賴項。但[Steven Francolla]的[其他解決方案](http://stackoverflow.com/questions/3421826/how-to-copy-dependencies-to-gae-war-web-inf-lib/3909756#3909756)卻有效。 – nikhil 2011-02-24 20:33:35