TimHedger wrote:
I've written a plugin (in Java) that explicitly invokes the main method of a
Java class directly from within the jvm that maven is already running.  My
plugin is behaving/configured as I expect, but I have a classpath problem
when control switches from my plugin code to the main method of the Java
class it invokes.

Seems like you have implemented the exec-maven-plugin [1].

I use the following method to print the classpath before I invoke the main
method on my target class:
project.getCompileClasspathElements();

(where project is MavenProject)

And I get the list of jars I expect, including:
/home/hedgert/.m2/repository/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar

which is the copy of javax.servlet that I have in my local maven repository. Great - so far so good.

I invoke the main method of my target class and the code runs and then falls
over with a:
java.lang.NoClassDefFoundError: javax/servlet/ServletException

If I check the contents of my servlet-api-2.4.jar:
: jar -tf
/home/hedgert/.m2/repository/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar
|grep ServletException
javax/servlet/ServletException.class

The missing class is indeed in the jar that is on the classpath.

So presumably the classpath I'm getting back from:
project.getCompileClasspathElements();

is not actually the classpath in operation when I invoke the main method on
my class from within a running JVM.

So my question is: maven has nicely worked out the classpath I need (using
the dependencies in my pom.xml file for my target project, rather than my
plugin), how do I get this classpath be active in the running JVM?

You don't. The classpath that the plugin is running in contains all dependencies of the plugin, not the project. If you want to do something with the project's classpath you will have to create a classloader from the list you're referring to.

[1]: http://mojo.codehaus.org/exec-maven-plugin/

--
Trygve

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to