You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Claudio Ranieri <cl...@buscape-inc.com> on 2008/05/20 15:06:58 UTC
Problem with classloader in maven plugin
Hi
I am trying to create a maven plugin to jboss wsconsume, but I have a problem with classloader in plugin.
My plugin is based in an ant task (WSConsumeTask).
I am using maven 2.0.8 on Windows machine.
When I created a simple Java project with libraries necessary, my code works.
How shown below:
public static void main(String[] args) {
WSConsumeTask t = new WSConsumeTask();
t.setWsdl("https://xxx/crypto?wsdl");
t.setVerbose(true);
t.setKeep(true);
t.execute();
}
But when I am using into maven plugin, I got problem with classloader.
I got this exception:
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:7: cannot find symbol
symbol : class Service
location: package javax.xml.ws
import javax.xml.ws.Service;
^
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:8: cannot find symbol
symbol : class WebEndpoint
location: package javax.xml.ws
import javax.xml.ws.WebEndpoint;
^
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:9: cannot find symbol
symbol : class WebServiceClient
location: package javax.xml.ws
import javax.xml.ws.WebServiceClient;
The plugin classloader doesn´t load the jaxws libraries. But this libraries was added in pom.xml of plugin.
I tried to add dependencies tag in my plugin config, but didn´t works. How shown below:
<plugin>
<groupId>jboss</groupId>
<artifactId>maven-jbossws-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<verbose>true</verbose>
<keep>true</keep>
<wsdl>https://xxx/crypto?wsdl</wsdl>
</configuration>
<dependencies>
<dependency>
<groupId>jboss.jbossws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>3.0.1-native-2.0.4.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jboss.jbossws</groupId>
<artifactId>jboss-jaxws</artifactId>
<version>3.0.1-native-2.0.4.GA</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
I tried too to use an initClassLoader based in jaxws-maven-plugin source, how shown below:
private String initClassLoader(ClassLoader parent) throws MojoExecutionException {
try {
List classpathFiles = project.getCompileClasspathElements();
URL[] urls = new URL[classpathFiles.size() + 4];
StringBuffer classPath = new StringBuffer();
for (int i = 0; i < classpathFiles.size(); ++i) {
getLog().debug((String)classpathFiles.get(i));
urls[i] = new File((String)classpathFiles.get(i)).toURL();
classPath.append((String)classpathFiles.get(i));
classPath.append(File.pathSeparatorChar);
}
urls[classpathFiles.size()] = new File(project.getBuild().getOutputDirectory()).toURL();
urls[classpathFiles.size() + 1] = getArtifact("jboss.jbossws:jboss-jaxws");
urls[classpathFiles.size() + 2] = getArtifact("jboss.jbossws:jaxws-tools");
File toolsJar = new File(System.getProperty("java.home"),"../lib/tools.jar");
if (!toolsJar.exists()) {
toolsJar = new File(System.getProperty("java.home"),"lib/tools.jar");
}
urls[classpathFiles.size() + 3] = toolsJar.toURL();
System.out.println("urls: "+Arrays.toString(urls));
URLClassLoader cl = new URLClassLoader(urls,parent);
// Set the new classloader
Thread.currentThread().setContextClassLoader(cl);
System.setProperty("java.class.path",classPath.toString());
String sysCp = System.getProperty("java.class.path");
return sysCp;
}
catch (MalformedURLException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
}
public void execute() throws MojoExecutionException {
// Need to build a URLClassloader since Maven removed it form the chain
ClassLoader parent = this.getClass().getClassLoader();
String originalSystemClasspath = this.initClassLoader( parent );
try {
// Execute WSConsumeTask
WSConsumeTask t = new WSConsumeTask();
t.setWsdl(wsdl);
t.setVerbose(verbose);
t.setKeep(keep);
t.execute();
}
finally {
// Set back the old classloader
Thread.currentThread().setContextClassLoader(parent);
System.setProperty("java.class.path",originalSystemClasspath);
}
}
But, it doesn´t works.
Please, can someone help me?
Thanks
RES: Problem with classloader in maven plugin
Posted by Claudio Ranieri <cl...@buscape-inc.com>.
Anyone?
I want help the open source community, but I have this problem with classloader.
-----Mensagem original-----
De: Claudio Ranieri [mailto:claudior@buscape-inc.com]
Enviada em: terça-feira, 20 de maio de 2008 10:07
Para: dev@maven.apache.org
Assunto: Problem with classloader in maven plugin
Hi
I am trying to create a maven plugin to jboss wsconsume, but I have a problem with classloader in plugin.
My plugin is based in an ant task (WSConsumeTask).
I am using maven 2.0.8 on Windows machine.
When I created a simple Java project with libraries necessary, my code works.
How shown below:
public static void main(String[] args) {
WSConsumeTask t = new WSConsumeTask();
t.setWsdl("https://xxx/crypto?wsdl");
t.setVerbose(true);
t.setKeep(true);
t.execute();
}
But when I am using into maven plugin, I got problem with classloader.
I got this exception:
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:7: cannot find symbol
symbol : class Service
location: package javax.xml.ws
import javax.xml.ws.Service;
^
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:8: cannot find symbol
symbol : class WebEndpoint
location: package javax.xml.ws
import javax.xml.ws.WebEndpoint;
^
C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:9: cannot find symbol
symbol : class WebServiceClient
location: package javax.xml.ws
import javax.xml.ws.WebServiceClient;
The plugin classloader doesn´t load the jaxws libraries. But this libraries was added in pom.xml of plugin.
I tried to add dependencies tag in my plugin config, but didn´t works. How shown below:
<plugin>
<groupId>jboss</groupId>
<artifactId>maven-jbossws-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<verbose>true</verbose>
<keep>true</keep>
<wsdl>https://xxx/crypto?wsdl</wsdl>
</configuration>
<dependencies>
<dependency>
<groupId>jboss.jbossws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>3.0.1-native-2.0.4.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jboss.jbossws</groupId>
<artifactId>jboss-jaxws</artifactId>
<version>3.0.1-native-2.0.4.GA</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
I tried too to use an initClassLoader based in jaxws-maven-plugin source, how shown below:
private String initClassLoader(ClassLoader parent) throws MojoExecutionException {
try {
List classpathFiles = project.getCompileClasspathElements();
URL[] urls = new URL[classpathFiles.size() + 4];
StringBuffer classPath = new StringBuffer();
for (int i = 0; i < classpathFiles.size(); ++i) {
getLog().debug((String)classpathFiles.get(i));
urls[i] = new File((String)classpathFiles.get(i)).toURL();
classPath.append((String)classpathFiles.get(i));
classPath.append(File.pathSeparatorChar);
}
urls[classpathFiles.size()] = new File(project.getBuild().getOutputDirectory()).toURL();
urls[classpathFiles.size() + 1] = getArtifact("jboss.jbossws:jboss-jaxws");
urls[classpathFiles.size() + 2] = getArtifact("jboss.jbossws:jaxws-tools");
File toolsJar = new File(System.getProperty("java.home"),"../lib/tools.jar");
if (!toolsJar.exists()) {
toolsJar = new File(System.getProperty("java.home"),"lib/tools.jar");
}
urls[classpathFiles.size() + 3] = toolsJar.toURL();
System.out.println("urls: "+Arrays.toString(urls));
URLClassLoader cl = new URLClassLoader(urls,parent);
// Set the new classloader
Thread.currentThread().setContextClassLoader(cl);
System.setProperty("java.class.path",classPath.toString());
String sysCp = System.getProperty("java.class.path");
return sysCp;
}
catch (MalformedURLException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
}
public void execute() throws MojoExecutionException {
// Need to build a URLClassloader since Maven removed it form the chain
ClassLoader parent = this.getClass().getClassLoader();
String originalSystemClasspath = this.initClassLoader( parent );
try {
// Execute WSConsumeTask
WSConsumeTask t = new WSConsumeTask();
t.setWsdl(wsdl);
t.setVerbose(verbose);
t.setKeep(keep);
t.execute();
}
finally {
// Set back the old classloader
Thread.currentThread().setContextClassLoader(parent);
System.setProperty("java.class.path",originalSystemClasspath);
}
}
But, it doesn´t works.
Please, can someone help me?
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Problem with classloader in maven plugin
Posted by Mauro Talevi <ma...@aquilonia.org>.
Try having a look at this example:
https://svn.codehaus.org/mojo/trunk/sandbox/fit-maven-plugin/src/main/java/org/codehaus/mojo/fit/
Cheers
Claudio Ranieri wrote:
> Hi
>
> I am trying to create a maven plugin to jboss wsconsume, but I have a problem with classloader in plugin.
> My plugin is based in an ant task (WSConsumeTask).
> I am using maven 2.0.8 on Windows machine.
> When I created a simple Java project with libraries necessary, my code works.
> How shown below:
>
> public static void main(String[] args) {
> WSConsumeTask t = new WSConsumeTask();
> t.setWsdl("https://xxx/crypto?wsdl");
> t.setVerbose(true);
> t.setKeep(true);
> t.execute();
> }
>
> But when I am using into maven plugin, I got problem with classloader.
> I got this exception:
>
> C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:7: cannot find symbol
> symbol : class Service
> location: package javax.xml.ws
> import javax.xml.ws.Service;
> ^
> C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:8: cannot find symbol
> symbol : class WebEndpoint
> location: package javax.xml.ws
> import javax.xml.ws.WebEndpoint;
> ^
> C:\eclipse\workspace\TestePluginMaven\output\com\buscape\bean\CryptoService.java:9: cannot find symbol
> symbol : class WebServiceClient
> location: package javax.xml.ws
> import javax.xml.ws.WebServiceClient;
>
> The plugin classloader doesn´t load the jaxws libraries. But this libraries was added in pom.xml of plugin.
> I tried to add dependencies tag in my plugin config, but didn´t works. How shown below:
>
> <plugin>
> <groupId>jboss</groupId>
> <artifactId>maven-jbossws-plugin</artifactId>
> <version>1.0.0</version>
> <configuration>
> <verbose>true</verbose>
> <keep>true</keep>
> <wsdl>https://xxx/crypto?wsdl</wsdl>
> </configuration>
> <dependencies>
> <dependency>
> <groupId>jboss.jbossws</groupId>
> <artifactId>jaxws-tools</artifactId>
> <version>3.0.1-native-2.0.4.GA</version>
> <scope>compile</scope>
> </dependency>
> <dependency>
> <groupId>jboss.jbossws</groupId>
> <artifactId>jboss-jaxws</artifactId>
> <version>3.0.1-native-2.0.4.GA</version>
> <scope>compile</scope>
> </dependency>
> </dependencies>
> </plugin>
>
> I tried too to use an initClassLoader based in jaxws-maven-plugin source, how shown below:
>
> private String initClassLoader(ClassLoader parent) throws MojoExecutionException {
> try {
> List classpathFiles = project.getCompileClasspathElements();
> URL[] urls = new URL[classpathFiles.size() + 4];
> StringBuffer classPath = new StringBuffer();
> for (int i = 0; i < classpathFiles.size(); ++i) {
> getLog().debug((String)classpathFiles.get(i));
> urls[i] = new File((String)classpathFiles.get(i)).toURL();
> classPath.append((String)classpathFiles.get(i));
> classPath.append(File.pathSeparatorChar);
> }
> urls[classpathFiles.size()] = new File(project.getBuild().getOutputDirectory()).toURL();
>
> urls[classpathFiles.size() + 1] = getArtifact("jboss.jbossws:jboss-jaxws");
>
> urls[classpathFiles.size() + 2] = getArtifact("jboss.jbossws:jaxws-tools");
>
> File toolsJar = new File(System.getProperty("java.home"),"../lib/tools.jar");
> if (!toolsJar.exists()) {
> toolsJar = new File(System.getProperty("java.home"),"lib/tools.jar");
> }
> urls[classpathFiles.size() + 3] = toolsJar.toURL();
>
> System.out.println("urls: "+Arrays.toString(urls));
>
> URLClassLoader cl = new URLClassLoader(urls,parent);
> // Set the new classloader
> Thread.currentThread().setContextClassLoader(cl);
> System.setProperty("java.class.path",classPath.toString());
> String sysCp = System.getProperty("java.class.path");
> return sysCp;
> }
> catch (MalformedURLException e) {
> throw new MojoExecutionException(e.getMessage(),e);
> }
> catch (DependencyResolutionRequiredException e) {
> throw new MojoExecutionException(e.getMessage(),e);
> }
>
> }
>
> public void execute() throws MojoExecutionException {
> // Need to build a URLClassloader since Maven removed it form the chain
> ClassLoader parent = this.getClass().getClassLoader();
> String originalSystemClasspath = this.initClassLoader( parent );
>
> try {
>
> // Execute WSConsumeTask
> WSConsumeTask t = new WSConsumeTask();
> t.setWsdl(wsdl);
> t.setVerbose(verbose);
> t.setKeep(keep);
> t.execute();
> }
> finally {
> // Set back the old classloader
> Thread.currentThread().setContextClassLoader(parent);
> System.setProperty("java.class.path",originalSystemClasspath);
> }
> }
>
> But, it doesn´t works.
> Please, can someone help me?
> Thanks
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org