【问题标题】:OSGi ClassNotFoundException WSServletContextListenerOSGi ClassNotFoundException WSServletContextListener
【发布时间】:2017-10-30 17:25:59
【问题描述】:

我正在编写一个包含 Web 服务服务器 (com.sun.xml.ws/jaxws-rt) 的 OSGi 包 (hu.libra.commons.osgi.core.wsbundle)。 这是可行的,但是生成的包包含 5Mb 的嵌入式 jar,我不想将它包含在我所有的 web 服务包中(毕竟 OSGi 是关于模块化的),我想把它们放入一个“webservice core”包中( hu.libra.commons.webservice.core) 和我所有的网络服务都将依赖于此。

但是当我尝试这样做时,我得到 java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener 异常。 有什么问题?

目前正在使用 pom.xml (hu.libra.commons.osgi.core.wsbundle)

<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">
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <bundlename>hu.libra.commons.osgi.core.wsbundle</bundlename>
</properties>

<organization>
    <name>Libra Szoftver Zrt.</name>
    <url>http://www.libra.hu</url>
</organization>

<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core-wsbundle</artifactId>
<version>1.7.0</version>
<name>Libra Common OSGi Core Webservice Bundle</name>
<packaging>war</packaging>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <Bundle-SymbolicName>${bundlename}</Bundle-SymbolicName>
                    <Private-Package>hu.libra.commons.osgi.core.wsbundle</Private-Package>   
                    <Import-Package>
                        org.osgi.framework,
                        javax.servlet,
                        javax.servlet.http,
                        hu.libra.commons.osgi.utils,
                        hu.libra.commons.osgi.core.service                          
                    </Import-Package>
                    <DynamicImport-Package>
                        javax.*,
                        org.xml.sax,
                        org.xml.sax.*,
                        org.w3c.*                           
                    </DynamicImport-Package>
                    <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath> 
                    <Embed-Directory>WEB-INF/lib</Embed-Directory>
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                    <Web-ContextPath>/libraosgicore</Web-ContextPath>
                    <Webapp-Context>/libraosgicore</Webapp-Context>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
    <finalName>${bundlename}-${project.version}</finalName>
</build>

<dependencies>
    <!-- OSGi -->
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>

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


    <!-- Libra OSGi Core Service -->
    <dependency>
        <groupId>hu.libra.commons</groupId>
        <artifactId>libra-commons-osgi-utils</artifactId>
        <version>1.7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>hu.libra.commons</groupId>
        <artifactId>libra-commons-osgi-core-service</artifactId>
        <version>1.7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

接下来的两个pom不工作,我得到java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener 异常。

pom.xml (hu.libra.commons.webservice.core)

<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">
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <bundlename>hu.libra.commons.webservice.core</bundlename>
</properties>

<organization>
    <name>Libra Szoftver Zrt.</name>
    <url>http://www.libra.hu</url>
</organization>

<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-webservice-core</artifactId>
<version>1.7.0</version>
<name>Libra Commons Webservice Core</name>
<packaging>bundle</packaging>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>jar</supportedProjectType>
                    <supportedProjectType>bundle</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <Bundle-SymbolicName>${bundlename}</Bundle-SymbolicName>                        
                    <Import-Package>
                        org.osgi.framework,
                        javax.servlet,
                        javax.servlet.http                          
                    </Import-Package>
                    <DynamicImport-Package>
                        javax.*,
                        org.xml.sax,
                        org.xml.sax.*,
                        org.w3c.*                           
                    </DynamicImport-Package>
                    <Export-Package>*</Export-Package>
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>                       
                </instructions>
            </configuration>
        </plugin>
    </plugins>
    <finalName>${bundlename}-${project.version}</finalName>
</build>
<dependencies>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.10</version>
    </dependency>
</dependencies>

pom.xml (hu.libra.commons.osgi.core.wsbundle)

<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">
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <bundlename>hu.libra.commons.osgi.core.wsbundle</bundlename>
</properties>

<organization>
    <name>Libra Szoftver Zrt.</name>
    <url>http://www.libra.hu</url>
</organization>

<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core-wsbundle</artifactId>
<version>1.7.0</version>
<name>Libra Common OSGi Core Webservice Bundle</name>
<packaging>war</packaging>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <Bundle-SymbolicName>${bundlename}</Bundle-SymbolicName>
                    <Private-Package>hu.libra.commons.osgi.core.wsbundle</Private-Package>
                    <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
                    <Web-ContextPath>/libraosgicore</Web-ContextPath>
                    <Webapp-Context>/libraosgicore</Webapp-Context>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
    <finalName>${bundlename}-${project.version}</finalName>
</build>

<dependencies>
    <!-- OSGi -->
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- Libra OSGi Core Service -->
    <dependency>
        <groupId>hu.libra.commons</groupId>
        <artifactId>libra-commons-osgi-utils</artifactId>
        <version>1.7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>hu.libra.commons</groupId>
        <artifactId>libra-commons-osgi-core-service</artifactId>
        <version>1.7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>hu.libra.commons</groupId>
        <artifactId>libra-commons-webservice-core</artifactId>
        <version>1.7.0</version>
        <scope>provided</scope>
    </dependency>       
</dependencies>

异常日志/堆栈跟踪

    java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
    at java.lang.ClassLoader.findClass(ClassLoader.java:530)
    at org.apache.felix.http.jetty.internal.WebAppBundleContext$1.findClass(WebAppBundleContext.java:54)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.eclipse.jetty.server.handler.ContextHandler.loadClass(ContextHandler.java:1681)
    at org.eclipse.jetty.webapp.StandardDescriptorProcessor.visitListener(StandardDescriptorProcessor.java:1897)
    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.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:83)
    at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.process(IterativeDescriptorProcessor.java:70)
    at org.eclipse.jetty.webapp.MetaData.resolve(MetaData.java:403)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1364)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-05-30 09:12:27.083:WARN:oejs.BaseHolder:Jetty HTTP Service: 
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServlet
    at java.lang.ClassLoader.findClass(ClassLoader.java:530)
    at org.apache.felix.http.jetty.internal.WebAppBundleContext$1.findClass(WebAppBundleContext.java:54)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
    at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:95)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-05-30 09:12:27.083:WARN:/libraosgicore:Jetty HTTP Service: unavailable
javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet
    at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:102)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-05-30 09:12:27.084:WARN:oejs.BaseHolder:Jetty HTTP Service: 
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServlet
    at java.lang.ClassLoader.findClass(ClassLoader.java:530)
    at org.apache.felix.http.jetty.internal.WebAppBundleContext$1.findClass(WebAppBundleContext.java:54)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
    at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:95)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:892)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-05-30 09:12:27.084:WARN:/libraosgicore:Jetty HTTP Service: unavailable
javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet
    at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:102)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:892)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2017-05-30 09:12:27.085:WARN:oejw.WebAppContext:Jetty HTTP Service: Failed startup of context o.a.f.h.j.i.WebAppBundleContext@42a7d0a{/libraosgicore,bundle://23.0:0/,UNAVAILABLE}{libraosgicore}
MultiException[javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet, javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet]
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:846)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Suppressed: 
    |javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet
    |   at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:102)
    |   at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    |   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    |   at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:892)
    |   at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    |   at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    |   at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    |   at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    |   at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    |   at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    |   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    |   at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    |   at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    |   at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    |   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    |   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    |   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    |   at java.lang.Thread.run(Thread.java:745)
Caused by: 
javax.servlet.UnavailableException: com.sun.xml.ws.transport.http.servlet.WSServlet
    at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:102)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.felix.http.jetty.internal.JettyService$4.doExecute(JettyService.java:817)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:976)
    at org.apache.felix.http.jetty.internal.JettyService$JettyOperation.call(JettyService.java:966)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

【问题讨论】:

  • 您应该从这些 POM 中删除 &lt;Import-Package&gt;&lt;DynamicImport-Package&gt; 部分。

标签: java web-services maven osgi classloader


【解决方案1】:

问题可能是 com.sun.xml 包在 Java 框架中 - 因为我知道 jaxws 运行时是随 JRE 一起提供的。 java框架包可以定义在容器的启动委托包中,也可以定义为框架扩展包。

示例扩展 Pom:

<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>
    <groupId>com.github.livesense</groupId>
    <artifactId>org.liveSense.parent</artifactId>
    <version>1.0.6-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>
  <version>1.0.6-SNAPSHOT</version>
<scm>
  <connection>scm:git:https://github.com/liveSense/org.liveSense.fragment.sun.misc.git</connection>
  <developerConnection>scm:git:https://github.com/liveSense/org.liveSense.fragment.sun.misc.git</developerConnection>
  <url>https://github.com/liveSense/org.liveSense.fragment.sun.misc</url>
  <tag>HEAD</tag>
</scm>
<artifactId>org.liveSense.fragment.sun.misc</artifactId>
<packaging>jar</packaging>
<name>liveSense :: Extension :: Sun misc</name>
<description>
        This bundle extends the System Bundle export
        list with the sun.misc package such
        that OSGi bundles may refer to Sun's misc implementation
        without the OSGi framework itself to provide it in a
        non-portable way.
</description>
<build>
  <plugins>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <forceCreation>true</forceCreation>
        <archive>
          <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
          <manifestEntries>
            <Export-Package>sun.misc</Export-Package>
          </manifestEntries>
        </archive>
      <configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <executions>
        <execution>
          <id>bundle-manifest</id>
          <phase>process-classes</phase>
          <goals>
            <goal>manifest</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <instructions>
          <Bundle-Category>liveSense</Bundle-Category>
          <Fragment-Host>system.bundle; extension:=framework</Fragment-Host>
        </instructions>
      </configuration>
    </plugin>
  </plugins>
</build>
</project>

你的 com.sun.misc 包可以通过 bundle 导入。

【讨论】:

  • 在使用导入和“org.osgi.framework.system.packages.extra”之后,ClassNotFoundException 消失了,现在我得到了“javax.servlet.UnavailableException: Servlet class com.sun.xml .ws.transport.http.servlet.WSServlet 不是 javax.servlet.Servlet”异常。这是否意味着我使用了两个版本的 javax.servlet.Servlet?我该如何解决这个问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2011-06-26
  • 1970-01-01
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
相关资源
最近更新 更多