开发者

NoClassDefFoundError on Web Application using two EAR's

开发者 https://www.devze.com 2023-02-03 15:23 出处:网络
I\'ve been stucked on an issue for a few days now, and I\'m about to give up. Need your help! :) Here\'s the thing:

I've been stucked on an issue for a few days now, and I'm about to give up. Need your help! :)

Here's the thing:

I'm working on a web application, and I'm trying to create the mobile version (at least the web services, using Jersey).

So now it looks like this:

  • Server
    • WebApp EAR
      • WebApp war
    • WebAppMobile EAR
      • WebAppMobile war

I think it's the best way to do it (any comment?).

I'm now using Jersey, to create easily my WebServices.

I successfuly managed to divide the web-contexts, and I can reach my resources, everything's fine. What I need to do now is to reach the WebApp packages from the WebAppMobile project. I've included the reference in the build path (using Eclipse), and it's compiling OK.

The only problem I have is I can't instantiate any object located in the WebApp war, it's giving me a NoClassDefFoundError :

Error 500: java.lang.NoClassDefFoundError: my.package.my.class

The weirdest thing is I can actually reach some of the objects' statics local variables, which means my app can see them... At least, I think it can..

I think this comes from the Jersey classpath, 'cause it's doing its own redirection to reach my resources. Here's my web.xml (from the WebAppMobile project) :

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>WebAppMobile</display-name>
    <servlet>
       <servlet-name>Jersey Web Application</servlet-name>
       <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.classpath</param-name>
            <param-value>my.webapp</param-value> (here's just a try)
        </init-param>
        <init-param> 
            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
            <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>my.webapp;my.webappmobile</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </s开发者_StackOverflowervlet>

    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/resources/*</url-pattern>
     </servlet-mapping>
</web-app>

Any clue? Is that even possible to have a connection between these two packages?

Thanks a lot!


I (temporary?) fixed it by creating a JAR from my WebApp project and including it in my WebAppMobile project. I then think there's no way to instantiate objects from another war, but if someone manages to do it, I'd be interested to know how :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号