2017-08-01 41 views
0

我其中有一個測試類Maven項目:ClassFormatError的ServletException Maven項目錯誤

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration({ 
    "file:../test-war/src/main/webapp/WEB-INF/applicationContext.xml", 
    "file:../test-war/src/main/webapp/WEB-INF/config/servlet-context.xml" 
}) 
@Transactional 
public class SpringTest { 

該項目與運行 「MVN乾淨安裝」 拋出錯誤:

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) 
    at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:161) 

已經嘗試了很多事情,但仍然無法工作,有什麼想法?

這是pom.xml中有關相關性:

<dependency> 
     <groupId>javaee</groupId> 
     <artifactId>javaee-api</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.javassist</groupId> 
     <artifactId>javassist</artifactId> 
     <version>3.20.0-GA</version> 
     </dependency> 
    <dependency> 
     <groupId>org.apache.geronimo.specs</groupId> 
     <artifactId>geronimo-servlet_3.0_spec</artifactId> 
     <version>1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <scope>test</scope> 
    </dependency> 

和依賴父母的pom.xml

<dependency> 
    <groupId>javaee</groupId> 
    <artifactId>javaee-api</artifactId> 
    <version>5</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.1.0</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.servlet.jsp</groupId> 
    <artifactId>javax.servlet.jsp-api</artifactId> 
    <version>2.3.1</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.validation</groupId> 
    <artifactId>validation-api</artifactId> 
    <version>1.0.0.GA</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.ejb3</groupId> 
    <artifactId>jboss-ejb3-ext-api</artifactId> 
    <version>1.0.0</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <version>4.3.7.Final</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-core</artifactId> 
    <version>4.3.7.Final</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-commons-annotations</artifactId> 
    <version>3.3.0.ga</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-annotations</artifactId> 
    <version>3.5.6-Final</version> 
    <scope>provided</scope> 
</dependency>    
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-validator</artifactId> 
    <version>3.1.0.GA</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>org.hsqldb</groupId> 
    <artifactId>hsqldb</artifactId> 
    <version>2.3.2</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.11</version> 
    <scope>test</scope> 

插件:

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.3.2</version> 
     <configuration> 
      <source>1.7</source> 
      <target>1.7</target> 
     </configuration> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <configuration> 
      <includes> 
       <include>**/MyTestSuite.class</include> 
      </includes> 
     </configuration> 
    </plugin> 
</plugins> 

試過很多選擇離子,去除測試範圍提供的所有東西等,但仍然會得到相同的錯誤。

回答

-1

的問題可能是由消失:

  • 重新排序/更新一些依賴
  • 創建新的依賴:
<dependency> 
    <groupId>org.apache.geronimo.specs</groupId> 
    <artifactId>geronimo-ejb_3.0_spec</artifactId> 
    <version>1.0.1</version> 
    <scope>test</scope> 
</dependency> 
-2

嘗試使用surefire plugin configuration<plugin>轉換爲pom.xml。你可以在下面找到插件:

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    <configuration> 
     <classpathDependencyExcludes> 
      <!-- exclude code absent api --> 
      <classpathDependencyExclude>javax.faces:javax.faces-api</classpathDependencyExclude> 
     </classpathDependencyExcludes> 
    </configuration> 
</plugin> 
+0

有類似的東西,但不幸(更新說明) – kandan