Fabio, The easiest thing would be to set up your classpath to include the relevant aspects for your nested child application to use. If you need to create a separate loader you can add them in there separately. I'd normally expect you'd want to use load-time weaving at the VM level with -javaagent as Matthew described. In unusual cases you might want to use the class org.aspectj.weaver.WeavingURLClassLoader to explicitly weave in a specific loader but I'd suggest you avoid that approach if possible.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stalsy Sent: Friday, October 27, 2006 1:10 AM To: [email protected] Subject: Re: [aspectj-users] lauching applications from anotherone with load-time weaving Hi Fabio, to launch an application from another java program it is possible using either reflection or create another process and execute java command with Runtime.getRuntime().exec(command); In both cases you can implement a programmatic version of aspectj compiler like the follow (as discussed at http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html): public class AspectWeaverImpl implements AspectWeaver { ... public void compile(boolean debug) throws AspectWeavingException { Main compiler = new Main(); MessageHandler m = new MessageHandler(); // call compiler parameters from XML file XMLReader xmlp = new XMLReaderImpl(Constants.configFilename); // call XML parser Vector v = xmlp.getArray("aj", "compilerParam"); String[] param = Utility.vectorTOString(v); // call ajc compiler.run(param, m); // print compiler verbose infos if (debug) { IMessage[] ms = m.getMessages(null, true); System.out.println("messages: " + Arrays.asList(ms)); } } } At this point you can chose two approaches (more complicated than using -javaagent but effective): 1) if you want use reflection put "-d" parameter in the compiler options. This parameter puts generated class files in a destination directory. Then you can recall your main class instance and invoke main method. 2) if you want use "Runtime.exec()" command you can insert "-outjar" parameter in the compile options. This parameter creates a jar file containing the generated output class file. So firstly you can recall your personal AspectWeaver (with -outjar option) and then launch the application (recall the jar file). regards Fabio Fagundes Silveira ha scritto: > *Hi Matthew, > > Ok ... but how to get this working? I just can get this working if > I type: java -javaagent:xxx Test ... Therefore, I dont know how to > load the other application (e.g. from App1.main) using a separate > class loader ... :-( > > ** Would you please send me some hints (piece of code)?* > * > Thank you, > Fabio > > On Thu, 26 Oct 2006 16:07:14 +0100, Matthew Webster wrote* > > Fabio, > > > > If you are using Java 5 then just use the -javaagent that comes with > AspectJ: > http://www.eclipse.org/aspectj/doc/released/devguide/ltw-agents.html. > You may want to load you test application using a separate class > loader, with it's own classpath. As each class is loaded it will > automatically get passes to AspectJ. > > > > Matthew Webster > > AOSD Project > > Java Technology Centre, MP146 > > IBM Hursley Park, Winchester, SO21 2JN, England > > Telephone: +44 196 2816139 (external) 246139 (internal) > > Email: Matthew Webster/UK/IBM @ IBMGB, [EMAIL PROTECTED] > > http://w3.hursley.ibm.com/~websterm/ > > > > > > > To [email protected] > > > cc > > > Subject [aspectj-users] lauching applications from another one with > load-time weaving > > > > > > > > > > > > > > > > Hello, > > > > To launch an application from another java program is possible using > > reflection, such as: > > > > Class cls = Class.forName("Test"); > > String s[] = new String[] {}; > > Object arguments[] = new Object[] { s }; > > Method mainMethod = cls.getMethod("main", new Class[] {s.getClass()}); > > Object result = mainMethod.invoke(null, arguments); > > > > Ok, but how to do that (ie. launching "Test" application) using > > load-time weaving? I meant, lauching Test and aspects defined to be > > applied to this class in a META-INF/aop.xml file? > > > > I've tried to find out any WeavingAdaptor tutorial or something like > > that ... but I didn't ... :-( > > > > Could you help me? :-) > > > > Regards, > > Fabio > > ------------------------------------------------------------------------ > > _______________________________________________ > aspectj-users mailing list > [email protected] > https://dev.eclipse.org/mailman/listinfo/aspectj-users > -- Stalsy HomePage --:. http://www.stalsy.it Blog --:. http://blog.stalsy.com Public Key --:. http://www.stalsy.it/key.php E-Mail --:. [EMAIL PROTECTED] MSN --:. [EMAIL PROTECTED] Skype --:. www.stalsy.it _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
