高枕无忧。没有找到类def

时间:2017-05-20 11:53:58

标签: java maven jboss wildfly resteasy

我正在使用 resteasy wildfly 构建rest-client。 根据堆栈跟踪,我可能会遇到家属问题 已经做过很多关于更改范围的尝试,删除或添加 pom.xml 中的依赖项并不会给出任何结果,除了另一个没有找到的堆栈跟踪... 这是我的

  

栈跟踪

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/GenericType
    at groupId.Main.<init>(Main.java:33)
    at groupId.Main.main(Main.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.GenericType
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

  

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <parent>
      <artifactId>restClient</artifactId>
      <groupId>groupId</groupId>
      <version>1.0-SNAPSHOT</version>
   </parent>

   <artifactId>rest-client</artifactId>
   <packaging>war</packaging>

   <name>restClient: WAR Module</name>

   <url>http://wildfly.org</url>
   <licenses>
      <license>
         <name>Apache License, Version 2.0</name>
         <distribution>repo</distribution>
         <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
      </license>
   </licenses>

   <dependencies>

      <!-- Dependency on the EJB module so we can use it's services if needed -->

       <!--&lt;!&ndash; https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs &ndash;&gt;-->

      <dependency>
         <groupId>org.jboss.resteasy</groupId>
         <artifactId>resteasy-client</artifactId>
         <version>3.1.2.Final</version>
          <scope>provided</scope>
      </dependency>
       <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>jaxrs-api</artifactId>

           <scope>provided</scope>
       </dependency>
       <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
       <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-jaxrs</artifactId>
           <version>3.1.2.Final</version>
           <scope>provided</scope>
       </dependency>

       <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-multipart-provider -->
       <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-multipart-provider</artifactId>
           <version>3.1.2.Final</version>
           <scope>provided</scope>
       </dependency>
       <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
       <!--<dependency>-->
       <!--<groupId>org.jboss.resteasy</groupId>-->
       <!--<artifactId>resteasy-jaxb-provider</artifactId>-->
       <!--<version>3.1.2.Final</version>-->
       <!--<scope>provided</scope>-->
       <!--</dependency>-->

       <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
       <!-- https://mvnrepository.com/artifact/javax.ejb/ejb-api -->



       <!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
       <dependency>
           <groupId>javax.enterprise</groupId>
           <artifactId>cdi-api</artifactId>
           <scope>provided</scope>
       </dependency>

       <!-- Import the JSF API, we use provided scope as the API is included in JBoss WildFly -->
       <dependency>
           <groupId>org.jboss.spec.javax.faces</groupId>
           <artifactId>jboss-jsf-api_2.2_spec</artifactId>
           <scope>provided</scope>
       </dependency>
       <!-- https://mvnrepository.com/artifact/javax.ejb/ejb-api -->
       <dependency>
           <groupId>javax.ejb</groupId>
           <artifactId>ejb-api</artifactId>
           <version>3.0</version>
       </dependency>

       <!-- Import the JPA API, we use provided scope as the API is included in JBoss WildFly -->
       <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
       <dependency>
           <groupId>org.hibernate.javax.persistence</groupId>
           <artifactId>hibernate-jpa-2.1-api</artifactId>

           <version>1.0.0.Final</version>

       </dependency>
       <!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
       <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
       <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-core</artifactId>
           <scope>provided</scope>
           <exclusions>
               <exclusion>
                   <groupId>dom4j</groupId>
                   <artifactId>dom4j</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
       <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
       <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-entitymanager</artifactId>
           <scope>provided</scope>
           <exclusions>
               <exclusion>
                   <groupId>dom4j</groupId>
                   <artifactId>dom4j</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
       <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
       <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-validator</artifactId>
           <scope>provided</scope>
       </dependency>

       <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
       <!--<dependency>-->
       <!--<groupId>org.postgresql</groupId>-->
       <!--<artifactId>postgresql</artifactId>-->
       <!--<version>42.1.0</version>-->
       <!--</dependency>-->

       <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
       <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider -->
       <dependency>
           <groupId>com.fasterxml.jackson.jaxrs</groupId>
           <artifactId>jackson-jaxrs-json-provider</artifactId>
           <version>2.9.0.pr3</version>
       </dependency>
       <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-xml-provider -->
       <dependency>
           <groupId>com.fasterxml.jackson.jaxrs</groupId>
           <artifactId>jackson-jaxrs-xml-provider</artifactId>
           <version>2.9.0.pr3</version>
       </dependency>

       <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
       <dependency>
           <groupId>commons-io</groupId>
           <artifactId>commons-io</artifactId>
           <version>2.5</version>
       </dependency>

   </dependencies>

   <build>
      <finalName>${project.artifactId}</finalName>
      <plugins>
         <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
               <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
               <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
         </plugin>
      </plugins>
   </build>

</project>

1 个答案:

答案 0 :(得分:0)

根据stacktrace,你在IntelliJ中运行一个main方法。

所有RESTEasy依赖项都标记为“已提供”。这意味着应用程序期望运行时容器(例如应用程序服务器)提供它们。 IntelliJ不会在运行时本身提供这些依赖项,因此您将收到ClassNotFoundException错误。

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

  

<强>提供

     

这很像编译,但表示您期望JDK   或者在运行时提供依赖性的容器。例如,何时   您可以为Java Enterprise Edition构建Web应用程序   设置对Servlet API和相关Java EE API的依赖   提供范围是因为Web容器提供了这些类。这个   scope仅在编译和测试类路径上可用,并且是   不是过渡性的。

要在IntelliJ中测试应用程序,只需删除提供的范围。