Hi,

you've missunderstood the concept of a context classloader.

A documentation bug [1] is open since a long time. Setting the context classloader doesn't mean that all classes created from that point on are created through this classloader. See here [2] and [3] for more information.

[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4868493
[2] http://www.javaworld.com/javaqa/2003-06/01-qa-0606-load.html
[3] http://www.javageeks.com/Papers/ClassForName/index.html

-Tim

Claudio Ranieri schrieb:
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to