*Attachement does not work so here are my sources.*
*
*
*package bundle.plugin;*
*
*
*/**
* * Copyright 2001-2005 The Apache Software Foundation.*
* **
* * Licensed under the Apache License, Version 2.0 (the "License");*
* * you may not use this file except in compliance with the License.*
* * You may obtain a copy of the License at*
* **
* *      http://www.apache.org/licenses/LICENSE-2.0*
* **
* * Unless required by applicable law or agreed to in writing, software*
* * distributed under the License is distributed on an "AS IS" BASIS,*
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* * See the License for the specific language governing permissions and*
* * limitations under the License.*
* */*
*
*
*import java.io.File;*
*import java.lang.reflect.Method;*
*import java.net.URL;*
*import java.net.URLClassLoader;*
*import java.util.ArrayList;*
*import java.util.List;*
*import java.util.ResourceBundle;*
*
*
*import org.apache.maven.plugin.AbstractMojo;*
*import org.apache.maven.plugin.MojoExecutionException;*
*import org.apache.maven.project.MavenProject;*
*
*
*/***
* * Goal which touches a timestamp file.*
* * *
* * @goal exec*
* * *
* * @phase process-sources*
* * *
* * @requiresProject true*
* */*
*public class MyMojo extends AbstractMojo*
*{*
*    /***
*     * @parameter expression="${project}*
*     */*
*    private MavenProject project;*
*
*
*    /***
*     * <i>Maven Internal</i>: List of artifacts for the plugin.*
*     * *
*     * @parameter expression="${plugin.artifacts}"*
*     * @requiresDependencyResolution compile*
*     * @required*
*     * @readonly*
*     */*
*    protected List pluginClasspathList;*
*    *
*    /***
*     * This is where the generated java sources are stored.*
*     * *
*     * @parameter
expression="${project.build.directory}/jasperreports/java"*
*     */*
*    private File javaDirectory;*
*    *
*    /***
*     * Any additional classpath entry you might want to add to the
JasperReports compiler. Not recommended for general*
*     * use, plugin dependencies should be used instead.*
*     * *
*     * @parameter*
*     */*
*    private String additionalClasspath;*
*
*
*    /***
*     * @parameter expression="${project.compileClasspathElements}"*
*     */*
*    private List classpathElements;*
*
*
*    public void execute() throws MojoExecutionException*
*    {*
*
*
*        StringBuilder classpath = new
StringBuilder(System.getProperty("java.class.path", ""));*
*        classpath.append("${plugin.artifacts}");*
*        System.setProperty("java.class.path", classpath.toString());*
*        getLog().info("********++++++++++++++++*************");*
*        getLog().info(System.getProperty("java.class.path"));*
*        ClassLoader classLoader =
getClassLoader(ClassLoader.getSystemClassLoader());*
*        Thread.currentThread().setContextClassLoader(classLoader);*
*        *
*        getLog().info("project " + javaDirectory);*
*        project.addCompileSourceRoot(javaDirectory.getAbsolutePath());*
*        try*
*        {*
*            Class ress =
classLoader.loadClass(ResourceBundle.class.getName());*
*           // getMethod( "run", List.class,*
*            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 (Exception e)*
*        {*
*            e.printStackTrace();*
*        }*
*       *
*       // ResourceBundle bundle =
ResourceBundle.getBundle("localisations");*
*       *
*    }*
*    *
*    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());*
*            }*
*        }*
*
*
*        if (additionalClasspath != null && additionalClasspath.length() >
0)*
*        {*
*            String[] elements =
additionalClasspath.split(File.pathSeparator);*
*            for (int i = 0; i < elements.length; i++)*
*            {*
*                String element = elements[i];*
*                try*
*                {*
*                    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
classpath " + additionalClasspath + " "*
*                                                     + e.getMessage());*
*                }*
*            }*
*        }*
*
*
*        URL[] urls = (URL[]) classpathURLs.toArray(new
URL[classpathURLs.size()]);*
*        return new URLClassLoader(urls, classLoader);*
*    }*
*}*


and the pom of my artifact

*<plugin>*
* **<groupId>bundle.plugin</groupId>*
* **<artifactId>test-bundle-plugin</artifactId>*
* **<version>1.0-SNAPSHOT</version>*
* **<configuration>*
* **<javaDirectory>${project.build.sourceDirectory}</javaDirectory>*
* **
<classpathElements>${project.compileClasspathElements}</classpathElements>*
* **</configuration>*
* **<executions>*
* **<execution>*
*
*
* **<phase>compile</phase>*
* **<goals>*
* **<goal>exec</goal>*
* **</goals>*
* **<inherited>false</inherited>*
* **<configuration>*
* **<javaDirectory>src/main/java</javaDirectory>*
* **
<classpathElements>${project.compileClasspathElements}</classpathElements>*
* **</configuration>*
* **</execution>*
* **</executions>*
* **</plugin>.*
*
*
Thanks in advance :)

On Tue, Jul 20, 2010 at 10:19 AM, anis chaaba <anis.cha...@gmail.com> wrote:

> And now ?
>
>
> On Mon, Jul 19, 2010 at 10:16 PM, Anders Hammar <and...@hammar.net> wrote:
>
>> No projects were attached...
>>
>> /Anders
>>
>> On Mon, Jul 19, 2010 at 11:42, anis chaaba <anis.cha...@gmail.com> wrote:
>>
>> > Hello everybody,
>> > What can I do to make my plugin use ressources of the project running
>> into
>> > it ?
>> > My test projects are attached to this mail.
>> > When executing the goal of my plugin i get
>> >  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)
>> > at bundle.plugin.MyMojo.execute(MyMojo.java:69)
>> >  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).
>> > Thanks in advance.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
>> > For additional commands, e-mail: users-h...@maven.apache.org
>> >
>>
>
>

Reply via email to