gpt4 book ai didi

java - ClassNotFoundException 异常

转载 作者:行者123 更新时间:2023-11-28 22:17:05 25 4
gpt4 key购买 nike

我已经使用 jersey 2 和 spring 4 开发了一个项目,但是我不得不用 jersey 1.19 替换 jersey 2,当我这样做时我得到一个名为“java.lang.ClassNotFoundException: com.sun.jersey.core .util.FeaturesAndProperties”,当在 tomcat 服务器上运行时。是否从 jersey 2 迁移到 jersey 1.19 导致此异常?谢谢

我的 web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<!-- Spring Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Jersey Servlet -->
<servlet>
<servlet-name>FITransXT</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<!-- Register resources and providers -->
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mobileware.fitransxt</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>FITransXT</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<!-- loading Spring Context for registering beans with ApplicationContext -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/FITransXT-servlet.xml</param-value>
</context-param>



</web-app>

我的 Pom.xml

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- <dependencyManagement>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
</dependencyManagement> -->
<parent>
<groupId>com.mobileware.fitransxt</groupId>
<artifactId>FITransXT</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>FITransXT-Impl</artifactId>
<dependencies>
<dependency>
<groupId>com.mobileware.fitransxt</groupId>
<artifactId>FITransXT-Type</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.mobileware.fitransxt</groupId>
<artifactId>FITransXT-BOImpl</artifactId>
<version>0.0.1</version>
</dependency>
<!-- <dependency>
<groupId>com.mobileware.fitransxt</groupId>
<artifactId>FITransXT-DaoImpl</artifactId>
<version>0.0.1</version>
</dependency> -->
<!-- Jersey core Servlet 2.x implementation -->
<!-- <dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
<scope>compile</scope>
</dependency> -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>

<!-- Jersey JSON Jackson (2.x) entity providers support module -->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>


<!-- Jersey extension module providing support for Spring 3 integration -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.ext/jersey-bean-validation -->


<!-- Spring Framework-4.x -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.1.RELEASE</spring.version>
<jersey.version>1.19</jersey.version>
<slf4j.version>1.7.2</slf4j.version>
<jdk.source.version>1.8</jdk.source.version>
<jdk.target.version>1.8</jdk.target.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

依赖树

-- maven-dependency-plugin:2.8:tree (default-cli) @ FITransXT-Web ---
[INFO] com.mobileware.fitransxt:FITransXT-Web:war:0.0.1
[INFO] +- com.mobileware.fitransxt:FITransXT-Impl:jar:0.0.1:compile
[INFO] | +- com.mobileware.fitransxt:FITransXT-Type:jar:0.0.1:compile
[INFO] | | +- (org.springframework:spring-context:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-context-support:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | | +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | | \- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] | +- com.mobileware.fitransxt:FITransXT-BOImpl:jar:0.0.1:compile
[INFO] | | +- com.mobileware.fitransxt:FITransXT-BOIntf:jar:0.0.1:compile
[INFO] | | | +- (com.mobileware.fitransxt:FITransXT-Type:jar:0.0.1:compile - omitted for duplicate)
[INFO] | | | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | | | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | | | +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | | | \- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] | | +- com.mobileware.fitransxt:FITransXT-DaoImpl:jar:0.0.1:compile
[INFO] | | | +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] | | | | \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] | | | +- com.mobileware.fitransxt:FITransXT-Dao:jar:0.0.1:compile
[INFO] | | | | +- (com.mobileware.fitransxt:FITransXT-Type:jar:0.0.1:compile - omitted for duplicate)
[INFO] | | | | +- mysql:mysql-connector-java:jar:5.1.6:compile
[INFO] | | | | +- org.apache.commons:commons-dbcp2:jar:2.1:compile
[INFO] | | | | | +- org.apache.commons:commons-pool2:jar:2.3:compile
[INFO] | | | | | \- (commons-logging:commons-logging:jar:1.2:compile - omitted for duplicate)
[INFO] | | | | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | | | | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | | | | +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | | | | \- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] | | | +- com.oracle:ojdbc6:jar:11.2.0:compile
[INFO] | | | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | | | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | | | +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | | | \- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] | | +- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] | | +- (log4j:log4j:jar:1.2.14:compile - omitted for conflict with 1.2.17)
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.3.4:compile
[INFO] | | | +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] | | | +- (commons-logging:commons-logging:jar:1.1.3:compile - omitted for conflict with 1.2)
[INFO] | | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | | \- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | +- com.sun.jersey:jersey-server:jar:1.19:compile
[INFO] | | \- (com.sun.jersey:jersey-core:jar:1.19:compile - omitted for duplicate)
[INFO] | +- com.sun.jersey:jersey-core:jar:1.19:compile
[INFO] | | \- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] | +- com.sun.jersey:jersey-servlet:jar:1.19:compile
[INFO] | | \- (com.sun.jersey:jersey-server:jar:1.19:compile - omitted for duplicate)
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.3:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.0:compile
[INFO] | | \- (com.fasterxml.jackson.core:jackson-core:jar:2.7.3:compile - omitted for duplicate)
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.7.3:compile
[INFO] | +- com.sun.jersey.contribs:jersey-spring:jar:1.19:compile
[INFO] | | \- (com.sun.jersey:jersey-servlet:jar:1.19:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-core:jar:4.3.1.RELEASE:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] | +- org.springframework:spring-context:jar:4.3.1.RELEASE:compile
[INFO] | | +- (org.springframework:spring-aop:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- org.springframework:spring-beans:jar:4.3.1.RELEASE:compile
[INFO] | | | \- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | \- org.springframework:spring-expression:jar:4.3.1.RELEASE:compile
[INFO] | | \- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-context-support:jar:4.3.1.RELEASE:compile
[INFO] | | +- (org.springframework:spring-beans:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-context:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | \- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-web:jar:4.3.1.RELEASE:compile
[INFO] | | +- (org.springframework:spring-aop:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-beans:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-context:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | \- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-aop:jar:4.3.1.RELEASE:compile
[INFO] | | +- (org.springframework:spring-beans:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | \- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-webmvc:jar:4.3.1.RELEASE:compile
[INFO] | | +- (org.springframework:spring-aop:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-beans:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-context:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-core:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-expression:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | | \- (org.springframework:spring-web:jar:4.3.1.RELEASE:compile - omitted for duplicate)
[INFO] | +- (com.google.code.gson:gson:jar:2.3.1:compile - omitted for duplicate)
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO] | +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for duplicate)
[INFO] | \- (org.json:json:jar:20160810:compile - omitted for duplicate)
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for conflict with 1.7.6)
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] \- org.json:json:jar:20160810:compile

编辑:在控制台上:

java.lang.ClassNotFoundException: com.sun.jersey.core.util.FeaturesAndProperties
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1116)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
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 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

最佳答案

处理这类问题的方法-

首先关闭您的 IDE 并从您的项目目录中删除 target、.setting 和 .classpath。

1) 仔细检查 pom.xml 中是否有多个相同但不同版本的依赖项,如果是,请将其删除并运行命令 mvn clean install -U。如果不行的话

2) 找到 .m2 目录并在此目录中搜索 lastupdate 文件并删除所有这些文件并运行命令 mvn clean install -U。如果不行的话

3) 删除 .m2 目录并清理并安装 maven。

关于java - ClassNotFoundException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com