Hi Jason! Thanks for spotting the jetty plugin. Jetty is now using an own classloader, but I looked at old versions and managed to get classworlds working the way I need it. There are a few hacks in the source, so maybe someone has a tip for making this code prettier.
LieGrue, strub PS: the full code of the new openjpa-maven-plugin version can be found here: git-clone http://ns1.backwork.net/git/openjpa-maven-plugin.git PPS: thanks to Rahul for providing the first release of the openjpa plugin and doing some additional reviews now. /** * This will prepare the current ClassLoader and add all jars and local * classpaths (e.g. target/classes) needed by the OpenJPA task. * * @throws MojoExecutionException */ protected void extendRealmClasspath() throws MojoExecutionException { ClassWorld world = new ClassWorld(); ClassRealm jpaRealm; try { jpaRealm = world.newRealm( "maven.plugin.openjpa" , Thread.currentThread().getContextClassLoader() ); } catch ( DuplicateRealmException e ) { throw new MojoExecutionException( "problem while creating new ClassRealm", e ); } Iterator itor = classpathElements.iterator(); while (itor.hasNext()) { File pathelem = new File( (String) itor.next() ); getLog().debug( "adding classpathElement " + pathelem.getPath() ); try { // we need to use 3 slashes to prevent windoof from interpreting 'file://D:/path' as server 'D' // we also have to add a trailing slash after directory paths URL url = new URL("file:///" + pathelem.getPath() + ( pathelem.isDirectory() ? "/" : "" ) ); jpaRealm.addConstituent( url ); } catch ( MalformedURLException e ) { throw new MojoExecutionException( "error in adding the classpath " + pathelem, e ); } } // set the new ClassLoader as default for this Thread Thread.currentThread().setContextClassLoader( jpaRealm.getClassLoader() ); } --- Jason van Zyl <[EMAIL PROTECTED]> schrieb am Mo, 13.10.2008: > Von: Jason van Zyl <[EMAIL PROTECTED]> > Betreff: Re: Accessing an artifacts classpath from a mojo? > An: "Maven Users List" <users@maven.apache.org> > Datum: Montag, 13. Oktober 2008, 18:28 > Look at the Jetty plugin, Jan has done most of the work > there and I'm > sure you can lift it all. > > On 13-Oct-08, at 8:23 AM, Mark Struberg wrote: > > > Hi! > > > > I currently face a very similar problem: I'd like > to check for a > > resource target/classes/META-INF/persistence.xml from > my plugin via > > the plugins classloader (need the JDBC config from > there). > > > > I'm currently messing around with Classworlds, but > haven't succeed > > so far. > > > > It would be a great if you can point us to a plugin > which has > > implemented such a mechanism already. I'd hate to > call java via the > > CommandLine for this :( > > > > > > txs and LieGrue, > > strub > > > > --- Brett Porter <[EMAIL PROTECTED]> > schrieb am Mo, 13.10.2008: > > > >> Von: Brett Porter <[EMAIL PROTECTED]> > >> Betreff: Re: Accessing an artifacts classpath from > a mojo? > >> An: "Maven Users List" > <users@maven.apache.org> > >> Datum: Montag, 13. Oktober 2008, 12:45 > >> How do you need to use it? It can be quite simple > to create > >> a > >> classloader for this, but it depends on how > it'll be > >> used. > >> > >> Cheers, > >> Brett > >> > >> On 13/10/2008, at 9:40 PM, Mark Derricutt wrote: > >> > >>> Hi all, > >>> > >>> I have a maven plugin I'm working on and I > want to > >> include the > >>> classpath > >>> (main, test, others...) of the artifact > calling the > >> plugin - am I > >>> going to > >>> have to spawn/fork a new java process and > include them > >> on the > >>> classpath > >>> somehow, or is their some mojo-magic that > takes care > >> of this? > >>> > >>> Mark > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > Thanks, > > Jason > > ---------------------------------------------------------- > Jason van Zyl > Founder, Apache Maven > jason at sonatype dot com > ---------------------------------------------------------- > > You are never dedicated to something you have complete > confidence in. > No one is fanatically shouting that the sun is going to > rise tomorrow. > They know it is going to rise tomorrow. When people are > fanatically > dedicated to political or religious faiths or any other > kind of > dogmas or goals, it's always because these dogmas or > goals are in doubt. > > -- Robert Pirzig, Zen and the Art of Motorcycle > Maintenance > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] __________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]