Java 部署 Web 应用程序时,出现异常 NoClassDefFoundError:LocalizableImpl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19061718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:47:33  来源:igfitidea点击:

When deploying a web application I get the exception NoClassDefFoundError:LocalizableImpl

javaweb-servicesmaventomcat

提问by monksy

I have a standard J2EE web application that includes web services. I'm using the webservices-rtlibrary to host the services. [See the maven dependency below]. However, I get the following exception at run time:

我有一个包含 Web 服务的标准 J2EE Web 应用程序。我正在使用webservices-rt库来托管服务。[请参阅下面的 maven 依赖项]。但是,我在运行时收到以下异常:

SEVERE: Exception sending context initialized event to listener instance of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
java.lang.NoClassDefFoundError: com/sun/xml/ws/util/localization/LocalizableImpl
    at com.sun.xml.ws.util.exception.JAXWSExceptionBase.<init>(JAXWSExceptionBase.java:63)
    at com.sun.xml.ws.transport.http.servlet.WSServletException.<init>(WSServletException.java:47)
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [...]
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.util.localization.LocalizableImpl
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 33 more

Maven WS Dependency

Maven WS 依赖

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>webservices-rt</artifactId>
        <version>1.4</version>
        <scope>compile</scope>
    </dependency>

Am I missing a library? I've tried adding jaxws-rt. However, that requires an additional repo [jboss]. I'm a bit leery of that, as that it introduces a lot of new libraries into the project.

我错过了图书馆吗?我试过添加jaxws-rt. 但是,这需要额外的 repo [ jboss]。我对此有点怀疑,因为它在项目中引入了许多新库。

回答by monksy

Declaring the JBoss repo doesn't automatically import the repo libraries. It simply makes the libraries available for importing.

声明 JBoss 存储库不会自动导入存储库库。它只是使库可用于导入。

Bottom line is that if you want to use a class that's in a library, then you have to pull the library into your project. If the library is in the JBoss repo, then you have to declare the JBoss repo.

底线是,如果您想使用库中的类,那么您必须将该库拉入您的项目中。如果库在 JBoss 存储库中,那么您必须声明 JBoss 存储库。

回答by sunysen

try

尝试

The JAX-WS dependency library “jaxws-rt.jar” is missing.

缺少 JAX-WS 依赖库“jaxws-rt.jar”。

Go here http://jax-ws.java.net/.

去这里http://jax-ws.java.net/

Download JAX-WS RI distribution.

下载 JAX-WS RI 发行版。

Unzip it and copy “jaxws-rt.jar” to Tomcat library folder “{$TOMCAT}/lib“.

解压并将“jaxws-rt.jar”复制到Tomcat库文件夹“{$TOMCAT}/lib”。

Restart Tomcat.

重启Tomcat。

回答by Youness Marhrani

For a maven, tomcat application try these dependencies in your pom.xml

对于 maven,tomcat 应用程序在 pom.xml 中尝试这些依赖项

<dependencies>
    <!-- jax-ws maven dependency -->
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.8</version>
    </dependency>
    <!-- servlet provided by tomcat -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.2.7</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.stream.buffer/streambuffer -->
    <dependency>
        <groupId>com.sun.xml.stream.buffer</groupId>
        <artifactId>streambuffer</artifactId>
        <version>1.5.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.7</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.ws/policy -->
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>policy</artifactId>
        <version>2.3.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.gmbal/gmbal-api-only -->
    <dependency>
        <groupId>org.glassfish.gmbal</groupId>
        <artifactId>gmbal-api-only</artifactId>
        <version>3.2.0-b003</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.ha/ha-api -->
    <dependency>
        <groupId>org.glassfish.ha</groupId>
        <artifactId>ha-api</artifactId>
        <version>3.1.9</version>
    </dependency>
</dependencies>

I hope this works for new people who will face this issue

我希望这适用于将面临此问题的新人

Regards

问候

回答by GMsoF

If you are using Maven, add below to your project should solve your problem:

如果您使用的是 Maven,请将以下添加到您的项目中应该可以解决您的问题:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.2</version>
</dependency>

You don't have to add others jar because it will automatically pull the rest of dependencies. I prefer to add the jar to my war instead of Tomcat lib. I think it is more portable.

您不必添加其他 jar,因为它会自动拉取其余的依赖项。我更喜欢将 jar 添加到我的战争中,而不是 Tomcat lib。我认为它更便携。