2016-05-24 74 views
0

我與Eclipse和Maven做這個estructure文件夾中的Java項目: enter image description here的.jar與Maven和Eclipse

好吧,當我做一個Maven安裝創建的.jar採取這種結構的文件夾:

enter image description here

因此,層次結構是不一樣的,並鏈接到圖像和CSS不起作用。

我告訴你的pom.xml的

enter code here 

http://maven.apache.org/xsd/maven-4.0.0.xsd「代碼> 4.0.0 com.wepall 帕勒 0.4.0 com.thoughtworks.xstream XStream的 com.thoughtworks.xstream XStream的 1.4.9 帕勒

 <!-- download source code in Eclipse, best practice --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <downloadSources>true</downloadSources> 
       <downloadJavadocs>false</downloadJavadocs> 
      </configuration> 
     </plugin> 

     <!-- Set a compiler level --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>${jdk.version}</source> 
       <target>${jdk.version}</target> 
      </configuration> 
     </plugin> 

     <!-- Maven Assembly Plugin --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <!-- get all project dependencies --> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <!-- MainClass in mainfest make a executable jar --> 
       <archive> 
        <manifest> 
         <mainClass>com.wepall.palle.MainApp</mainClass> 
        </manifest> 
       </archive> 

      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <!-- bind to the packaging phase --> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

任何想法?

非常感謝! 最好的問候

+0

你能成爲一個更具體一點??? –

+0

是的,對不起,mi問題是關於.jar的herarky文件夾, 我解釋你, – wepall

+0

當我讓.jar沒有生成具有該項目的層次結構時,src的原始結構是src \ main \ java \ com \ wepall \ palle和src \ main \ resources ,最後是在java文件夾內,資源文件夾位於同一個文件夾中。 什麼時候它必須是一個java的文件夾和一個com文件夾(包含類)和其他資源以及文件夾css,Images,lib,Projects,RobotFiles內部。 – wepall

回答

0

您應該添加一個生成部分,將的pom.xml:

<build> 
     <directory>${basedir}/target</directory> 
     <resources> 
      <resource> 
       <targetPath>${basedir}/target/resources</targetPath> 
       <directory>${basedir}/src/main/resources</directory> 
      </resource> 
     </resources> 
</build> 

進一步參考: POM Reference (Build Section)

+0

非常感謝您的回覆,現在這個代碼的目標是很好的構建,但不是.jar,資源不在.jar – wepall

+0

解決!使用相同的代碼,但是: $ {basedir}/target/classes/resources現在jar具有與項目相同的文件夾層次結構。非常感謝你的幫助!!!! – wepall

0

我認爲你應該創建一個war代替jar,因爲你是在談論CSS和圖像罐子不應該包含類型的文件(見jar vs war)的。

在maven中,您只需要更改POM中項目的<packaging>