2017-06-14 55 views
0

我有兩個java項目,動物項目和動物測試項目。在動物項目,我有如下圖所示無法運行依賴主要功能

Animal.java

package com.animal; 

import java.lang.annotation.ElementType; 
import java.lang.annotation.Retention; 
import java.lang.annotation.RetentionPolicy; 
import java.lang.annotation.Target; 

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.TYPE) 
public @interface Animal{ 
    String name(); 
} 

隨着這個我有一個接口MakeSound.java其中有一個名爲動物像註釋界面一種稱爲的方法makesSound()

現在我已經建立並創建動物 jar文件,包括相關性,然後我在我的第二個項目動物試驗進口animal.jar。我創建了一個名爲AnimalTest.java 類我現在建立和創建一個JAR文件動物Test.jar的,當我運行jar文件中像Java的罐子動物Test.jar的我得到了以下異常

no main manifest attribute, in animal-test.jar 

任何人都可以請幫助我。

+0

貌似主類的屬性是不存在'META-INF/MANIFEST.MF'您可以檢查是否進入'主類:com.animal.AnimalFinder'出現在MANIFEST.MF文件在罐子裏? –

+0

你是怎麼創造這個罐子的? –

+0

@JerinJoseph我正在使用'mvn clean install' –

回答

2

您還需要添加插件以在pom.xml中爲動物測試創建MANIFEST文件。

<build> 
    <plugins> 
     <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.animal.AnimalFinder</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

讓我試試這個 –

+0

我有兩個罐子'animal-1.0.jar'和'animal-1.0-jar-with-dependencies.jar'。當我運行'java -jar animal-1.0-jar-with-dependencies。jar'我得到了'錯誤:無法找到或加載主類com.animal.AnimalFinder' –

+0

能否請你幫我在這https://stackoverflow.com/questions/44582091/one-jar-with-one-class-和主類從-dependecy-JAR –