Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using a Java Agent (e.g. Spring/Toplink) with an Eclipse RCP app?
Using a Java Agent (e.g. Spring/Toplink) with an Eclipse RCP app? [message #459373] Thu, 30 November 2006 16:15 Go to next message
Eclipse UserFriend
Originally posted by: mbayly.telus.net

Hi

I'm trying to get Spring+JPA+Toplink working in an Eclipse RCP app.

After much hairpulling I can now get it to work in a standalone Java app but have run into problems with Spring's InstrumentationLoadTimeWeaver trying to make it work in a plug-in environment.

The problem seems to be that Spring does not recognize that I've registered a javaagent to allow it to do its weaving magic.

The Spring agent saves off the JVM's Instrumentation implementation when the app starts. It then uses the 'saved' Instrumentation reference to set up class transformers later on in the app lifecycle.

The agent is set up using the javaagent vmarg

e.g.
-javaagent:${project_loc}/spring-agent.jar

The Spring agent contains the following code:

/**
 * Java agent that saves the Instrumentation interface
 * from the JVM for later use.
 *
 * @author Rod Johnson
 * @since 2.0
 * @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
 */
public class InstrumentationSavingAgent {
	
	private static Instrumentation instrumentation;


	/**
	 * Save the Instrumentation interface exposed by the JVM.
	 */
	public static void premain(String agentArgs, Instrumentation inst) {
		instrumentation = inst;
	}


	/**
	 * Return the Instrumentation interface exposed by the JVM.
	 */
	public static Instrumentation getInstrumentation() {
		return instrumentation;
	}

}


However, after the app has started, Spring complains that the agent was not initialized. I'm guessing it's a classloader problem. The class that was initialized by the JVM startup and the class that is subsequently loaded by Spring to get access to the instrumentation impl are being loaded by different, unrelated classloaders.

According to the Instrumentation API docs, the agent class will be loaded by the same classloader which loads the class containing the application main method and the agent jar file will be appended to the classpath.

What is the relationship between the Eclipse app class loader and the subsequent plug-in class loaders?

How can I ensure that the JVM initializes the same instance of the class that will be subsequently loaded by Spring (i.e. by my plug-in app's classloader)? Currently I have the spring jar's included directly in my Eclipse RCP app plug-in project. However, ultimately I'd like to include them as a separate plug-in which is depended upon by my app plug-in.

Or is there another way that I can save off the Instrumentation impl and get access to it later. Then use that ability to create my own weaver that I configure Spring to use?

I also notice that the TopLink Essentials agent which is used to enable lazy loading in toplink also utilizes a similar technique and hence also is not being initialized properly.

I guess a more general way of asking this question is how do you utilize java.lang.instrument in an Eclipse RCP app.

Hope this makes some sense to someone out there.

Thanks
Martin
Re: Using a Java Agent (e.g. Spring/Toplink) with an Eclipse RCP app? [message #459377 is a reply to message #459373] Thu, 30 November 2006 17:08 Go to previous message
Eclipse UserFriend
Originally posted by: mbayly.telus.net

Managed to get a bit further with this. Came across additional Buddy policies of boot, ext, app etc.

I found that by adding the app Buddy policy to my plugin and removing the Spring InstrumentationSavingAgent class from all but the spring-agent.jar referenced on vm start up, I could force it to load the version of InstrumentationSavingAgent used by the start up code and hence the Spring InstrumentationLoadTimeWeaver gets initialized properly.

Cheers
Martin
Previous Topic:How to open an login dialog before the Window is initialized
Next Topic:Toolbar visibility
Goto Forum:
  


Current Time: Thu Apr 17 12:14:45 EDT 2025

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

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

Back to the top