2017-02-19 69 views
0

我是新來的java和目前正在做一個java項目。這是如何提交項目的說明。誰能告訴我如何在intelliJ或eclipse中做到這一點?如何在intelliJ或eclipse中創建包含所有類和字節代碼的JAR文件?

請提交一個Java歸檔文件(jar文件,其中包含您編寫的所有java類)。 JAR文件應包含 : a)載源代碼,所有的類 b)載可執行文件(字節碼)的所有類

+0

你得到答案的問題嗎?如果是這樣,請考慮接受它,否則添加更多的細節問題。 – CrazyCoder

回答

0

這個問題已經already answered heremultiple times

由於您還需要包含來源,因此您必須更改resource patterns,以便.java文件也被複制到編譯器輸出,因此包含在.jar文件中。

默認情況下.java文件被排除在複製,所以你需要刪除!?*.java;模式排除他們:

exclude

!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj;!?*.aj

成爲

!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj;!?*.aj

別t忘記ch讓它迴歸真實世界的應用。

如果您需要IntelliJ IDEA的示例項目,可以下載它from my another answer。它顯示了一個更復雜的例子,其中使用不同的方式(單個罐子和多個罐子)將附加的獨立罐子包括到項目中。

+1

爲什麼這會被任何人低估?我投了票。 – duffymo

0

如果您使用的是eclipse,您可以按照您的要求採用以下方法之一。

要導出您正在爲JAR項目:

1)右鍵點擊你正在工作的項目>選擇出口從上下文菜單中。

enter image description here

2)選擇Java> JAR文件

enter image description here

3)選擇項目導出爲JAR。輸入生成jar文件的名稱,然後單擊完成。

enter image description here

如果您正在使用Maven的做如下配置到pom.xml中

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.4.1</version> 
    <configuration> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <archive> 
      <manifest> 
       <mainClass>com.xxxxx.xxxxx</mainClass> 
      </manifest> 
     </archive> 
     <outputDirectory>C:\tmp</outputDirectory> 
    </configuration> 
    <executions> 
     <execution> 
      <id>make-assembly</id> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-source-plugin</artifactId> 
    <version>3.0.1</version>  
    <configuration> 
     <outputDirectory>C:\tmp</outputDirectory> 
    </configuration>  
    <executions> 
     <execution> 
      <id>attach-sources</id> 
      <goals> 
       <goal>jar</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
相關問題