You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by anis chaaba <an...@gmail.com> on 2010/07/23 12:36:10 UTC

Maven Classloading : Custom Classloaders

Hello,
I'm developing a plugin which is supposed  to create a classloader that
combines the plugin class path and the project class path. Is there samples
for that ?

What i did is :

 public void execute() throws MojoExecutionException
    {

        ClassLoader classLoader = *getClassLoader*
(ClassLoader.getSystemClassLoader());
        try
        {
            Class ress =
classLoader.loadClass(ResourceBundle.class.getName());
            Method getB = ress.getMethod("getBundle", new Class[]
{String.class});
            ResourceBundle bundle = (ResourceBundle) getB.invoke(null, new
Object[] {"localisations"});
            getLog().info(bundle.getString("appli.web.root"));
        }
        catch (ClassNotFoundException e)
        {...
  }

  private ClassLoader *getClassLoader*(ClassLoader classLoader) throws
MojoExecutionException
    {
        List classpathURLs = new ArrayList();

        for (int i = 0; i < classpathElements.size(); i++)
        {
            String element = (String) classpathElements.get(i);
            try
            {
                getLog().info("classpathElements " + element);
                File f = new File(element);
                URL newURL = f.toURI().toURL();
                classpathURLs.add(newURL);
                getLog().debug("Added to classpath " + element);
            }
            catch (Exception e)
            {
                throw new MojoExecutionException("Error parsing classparh "
+ element + " " + e.getMessage());
            }
        }

        URL[] urls = (URL[]) classpathURLs.toArray(new
URL[classpathURLs.size()]);
        return new URLClassLoader(urls, classLoader);
    }


Logs are

*java.lang.reflect.InvocationTargetException*
* **at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
* **at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
*
* **at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
*
* **at java.lang.reflect.Method.invoke(Method.java:597)*
* **at bundle.plugin.MyMojo.execute(MyMojo.java:66)*
* **at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
*
* **at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
*
* **at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)*
* **at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)*
* **at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)*
* **at
org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)*
* **at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
* **at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
*
* **at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
*
* **at java.lang.reflect.Method.invoke(Method.java:597)*
* **at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)*
* **at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)*
* **at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
*
* **at org.codehaus.classworlds.Launcher.main(Launcher.java:375)*
*Caused by: java.util.MissingResourceException: Can't find bundle for base
name localisations, locale fr_FR*
* **at
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1521)
*
* **at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1260)*
* **at java.util.ResourceBundle.getBundle(ResourceBundle.java:715)*
* **... 24 more*