Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Classloader issue
Classloader issue [message #554611] Mon, 23 August 2010 16:54 Go to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

I have a jar that I can't embed in a RCP application for license reasons.

I try several things and only one works but It implies to embed the jar.

What works:
- add the jar in the plugin, add it to the plugin classpath and export its packages

What give ClassNotFoundException:
- add "-bootclasspath" argument when launching the framework
- add "-classpath" argument when launching the framework
- try to do it programmatically
ClassLoader currentClassLoader  = Thread.currentThread().getContextClassLoader();
ClassLoader classLoaderWithEndorsedLibs = new URLClassLoader(new URL[]{URLOfMyAddedJar} , currentClassLoader );
try {
    Thread.currentThread().setContextClassLoader(classLoaderWithEndorsedLibs);
   /*do my work which requires the jar*/
} catch(){...}finally{
   Thread.currentThread().setContextClassLoader(currentClassLoader );
}


- add it in jre/lib/ext of the JVM

I'm using Eclipse 3.6.0 and sun jvm 1.6u20

Thanks for any hints.

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team

[Updated on: Mon, 23 August 2010 16:54]

Report message to a moderator

Re: Classloader issue [message #554620 is a reply to message #554611] Mon, 23 August 2010 17:49 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
Are there reasons you don't want to go with the embedded jar route? That is the best option for you.

I am surprised the boot classpath option did not work. By default eclipse 3.6 should be delegating to the boot class loader as a last resort after normal OSGi delegation.

The -classpath option will not work because the applicaition class loader is not included in the hierarchy for OSGi bundle class loaders. The context class loader trick will not work unless the code you are running while in the try block actually uses the thread context class loader. The thread context class loader is not automatically searched.

Tom.
Re: Classloader issue [message #554701 is a reply to message #554620] Tue, 24 August 2010 07:05 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Thanks for your answer.

Thomas Watson wrote on Mon, 23 August 2010 19:49
Are there reasons you don't want to go with the embedded jar route?


There are license reason. Sad

Thomas Watson wrote on Mon, 23 August 2010 19:49

That is the best option for you.


Technically, I'm totally agree.

Thomas Watson wrote on Mon, 23 August 2010 19:49

I am surprised the boot classpath option did not work. By default eclipse 3.6 should be delegating to the boot class loader as a last resort after normal OSGi delegation.


I was surprised too. I will try again and double-check that I put the right value to the bootclasspath

Thomas Watson wrote on Mon, 23 August 2010 19:49

The -classpath option will not work because the application class loader is not included in the hierarchy for OSGi bundle class loaders. The context class loader trick will not work unless the code you are running while in the try block actually uses the thread context class loader. The thread context class loader is not automatically searched.


Thanks for the explanation.



Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Classloader issue [message #554771 is a reply to message #554611] Tue, 24 August 2010 11:43 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Ok, I retry using bootclasspath and it works. Smile

BTW I need to specify a list of jars. The java help tells that we can specify a directory but it doesn't work.
Is the directory must contain .class and not .jar?


Regards


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Classloader issue [message #554829 is a reply to message #554771] Tue, 24 August 2010 13:42 Go to previous message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
yes I think -bootclasspath must point to directories that contain .class files (along with their package directories) or must point to .jar files.

Tom.
Previous Topic:P2 and Helios RCP app SW Update Fails
Next Topic:P2 - Nullpointer Exception at RepositoryTransport.download
Goto Forum:
  


Current Time: Fri Apr 19 07:10:34 GMT 2024

Powered by FUDForum. Page generated in 0.02007 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top