2013-07-11 44 views
0

我有我的項目層次結構如下圖所示如何使用maven構建唯一的java文件?

myProject--->POM.xml 
myProject--->src--->main--->java---> java files under different sub directories 
myProject--->src--->main--->resources---> non java files under different sub directories 
myProject--->src--->main--->webApp---> non java files under different sub directories 

我要建立的項目,使構建只java文件,只包括在最終的jar文件中相應的類文件

這是我從相關代碼pom.xml但它沒有找到任何java文件來編譯。我不確定我在這裏錯過了什麼?

<build> 
    <pluginManagement> 
    <plugins> 
      <plugin> 
      <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
       <verbose>true</verbose> 
        <includes> 
          <include>**/*.java</include> 
          </includes> 
       </configuration> 
      </plugin> 
    </plugins> 
</pluginManagement> 
</build> 

更新: -我得到的信息消息 No sources to compile但也有子目錄

+0

爲什麼jar插件會包含.java文件?這些是源文件。你的意思是* .class?另外,你爲什麼不把資源包含在你的戰爭中? – Kayaman

+0

是的,你是對的。更正了我的帖子 – emilly

+0

你的maven-compiler-plugin的配置是什麼? – Kayaman

回答

0

的java文件我假設你想擺脫的文件像.xml.xhtml.properties等? 嘗試添加

<resources/> 

或者,您可以禁用執行,在這裏看到:

How to speed up Maven builds by 30 %: Supressing unused plugin executions

禁止的resource:default-resourceswar:default-war處決。

其實你不得不因爲war插件不服從<resources>

不過,jar插件將添加META-INF dir。可以使用clean插件在package階段之前刪除。

檢查this page進一步研究。

+0

我想擺脫除java文件之外的所有文件(不僅是資源) – emilly

+0

你能告訴我在pom.xml的build標籤下添加的位置嗎 – emilly

+0

選中此項:http://maven.apache.org/guides/introduction /introduction-to-the-pom.html –

0

您可以爲您的Java文件構建在這樣的加資源:

<build> 
<resources> 
    <resource> 
    <directory>src/main/java</directory> 
    </resource>  
</resources> 

而且你可能需要把你的java文件到你的輸出目錄。並刪除包含。

+0

它包含了一切,如屬性,js,jar文件中的xsr文件。所以它不起作用 – emilly

+0

我發現了一個可能的副本在這個http://stackoverflow.com/questions/2916091/adding-java-source-java-files-to-test-jar-in-maven –

+0

你需要移動你的java文件輸出目錄。使用maven-ant-plugin複製文件 –

相關問題