Embedded Jetty not loading jar file in clipse

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Embedded Jetty not loading jar file in clipse

aimran50
Hi,
I am trying to run jetty embedded inside an eclipse plugin. The war file is
loaded from the code as:
...
server = new Server();        
listener = new SocketListener();
server.addWebApplication("myapp","app.war");
...
The war file has additional jars in the WEB-INF/lib directory. The servlets
refer to the classes inside these jars.
When I launch the app from a standard java app, everything works fine, the
classes inside the jars are found and jetty is able to laod the app.
However, when launched within the eclipse plugin, jetty starts but fails to run
the servlets. I get a "java.lang.NoClassDefFoundError". I tried the
"server.getContext("myapp").setClassLoaderJava2Compliant(true);" but that didnt
help.
I am baffled what changes in the classloader that is preventing it to load the
jars from the lib directory when run from the eclipse plugin.
I tried printing the class path
- from java
jar:file:/E:/apps/app.war!/WEB-INF/classes/
- from eclipse:
jar:bundleresource://2/app.war!/WEB-INF/classes/
but nothing seems wrong here!?
Do I need to provide another class loader when running from eclipse? If yes,
which one and how do I set it?
Any help will be greatly appreciated.



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Embedded Jetty not loading jar file in clipse

Heiner Westphal
Hello Ai (or is it Aimran?)!

Finally another victim! I guess.

The NoClassDefFound does not always mean, that a class is not found!
In your case it probably means, the class can be found, but it cannot
be loaded, since another classloader already has it - loaded from
another jar.
Unfortunatly you may not access that classloader's classes.

I "solved" the problem by throwing away any logging related jars
(log4j and jakarta commons logging) and adding plugin dependencies
to org.apache.jakarta_commons_logging (jetty 5 uses it) and
org.apache.jakarta_log4j_logging (not necessary if you don't want
log4j behind JCL).
You can keep the logging jars, if you want, eclipse does not touch
them, if they do not appear inside the runtime section of your
plugin.xml.

My case is more complex in that jetty resides inside a plugin used
by another plugin and hivemind comes into play (in its own eclipse
plugin with some classloader magic to stop it breaking our app when
running inside a plugin).
Now I can use log4j inside my app, but fail to capture jetties, and
hiveminds, logs which go to java1.4 logging (JCL automatics if no log4j
found).
Putting the log4j dependency on the plugin containing jetty, or
hivemind, broke classloading of log4j classes in the outermost plugin.

If I get the time, I will do some more experiments to get jetties logs
into the log4j (or now nlog4j -> http://slf4j.org/) framework.

Regards,

Heiner

IA wrote:

> Hi,
> I am trying to run jetty embedded inside an eclipse plugin. The war file is
> loaded from the code as:
> ...
> server = new Server();        
> listener = new SocketListener();
> server.addWebApplication("myapp","app.war");
> ...
> The war file has additional jars in the WEB-INF/lib directory. The servlets
> refer to the classes inside these jars.
> When I launch the app from a standard java app, everything works fine, the
> classes inside the jars are found and jetty is able to laod the app.
> However, when launched within the eclipse plugin, jetty starts but fails to run
> the servlets. I get a "java.lang.NoClassDefFoundError". I tried the
> "server.getContext("myapp").setClassLoaderJava2Compliant(true);" but that didnt
> help.
> I am baffled what changes in the classloader that is preventing it to load the
> jars from the lib directory when run from the eclipse plugin.
> I tried printing the class path
> - from java
> jar:file:/E:/apps/app.war!/WEB-INF/classes/
> - from eclipse:
> jar:bundleresource://2/app.war!/WEB-INF/classes/
> but nothing seems wrong here!?
> Do I need to provide another class loader when running from eclipse? If yes,
> which one and how do I set it?
> Any help will be greatly appreciated.
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Embedded Jetty not loading jar file in clipse

Greg Wilkins-5
In reply to this post by aimran50

Try configuring Jetty to extract the war.

Jetty can run a war unpack as it has some support for jar:file URLs.

There is some chance that it will also work for jar:bundleresource: URLs,
but I doubt it will be fully functional.

cheers




IA wrote:

> Hi,
> I am trying to run jetty embedded inside an eclipse plugin. The war file is
> loaded from the code as:
> ....
> server = new Server();        
> listener = new SocketListener();
> server.addWebApplication("myapp","app.war");
> ....
> The war file has additional jars in the WEB-INF/lib directory. The servlets
> refer to the classes inside these jars.
> When I launch the app from a standard java app, everything works fine, the
> classes inside the jars are found and jetty is able to laod the app.
> However, when launched within the eclipse plugin, jetty starts but fails to run
> the servlets. I get a "java.lang.NoClassDefFoundError". I tried the
> "server.getContext("myapp").setClassLoaderJava2Compliant(true);" but that didnt
> help.
> I am baffled what changes in the classloader that is preventing it to load the
> jars from the lib directory when run from the eclipse plugin.
> I tried printing the class path
> - from java
> jar:file:/E:/apps/app.war!/WEB-INF/classes/
> - from eclipse:
> jar:bundleresource://2/app.war!/WEB-INF/classes/
> but nothing seems wrong here!?
> Do I need to provide another class loader when running from eclipse? If yes,
> which one and how do I set it?
> Any help will be greatly appreciated.
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support