繁体   English   中英

高枕无忧。 找不到类def

[英]Resteasy. Class def not found

我正在用resteasywildfly构建rest-client。 根据stacktrace可能我有依赖项问题。
已经进行了很多有关更改范围的尝试,删除或添加pom.xml中的依赖项不会产生任何结果,除了另一个未找到内容的stacktrace ...
这是我的

堆栈跟踪

    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>

根据堆栈跟踪,您正在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容器提供了这些类。 该作用域仅在编译和测试类路径上可用,并且不可传递。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM