Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] running compiler in java application


D'oh ! I made a mistake in the sample code. The for loop at the end has an incorrectly named variable. For clarity, please change variable identifier "problemMessages" to "problems" like this ...


                // Now just process the messages ....
              for (int i=0 ; i<problems.length ;i++)

               {

                   ISourceLocation s = problems[i].getSourceLocation();  
                   .. etc ... etc ...


               }// end for

Best regards,
George
________________________________________
George C. Harley



George Harley1/UK/IBM@IBMGB
Sent by: aspectj-users-admin@xxxxxxxxxxx

10/12/2004 10:15

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
Re: [aspectj-users] running compiler in java application






Dear Sir,


Yes, it is possible using the AspectJ compiler API (see http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/devguide/ajc-ref.html#d0e575). The way I have used it in the past looks something like this ...



           // Create a new Main together with a message holder to enable access to any compiler messages.

           org.aspectj.tools.ajc.Main ajCompiler = new Main();

           org.aspectj.bridge.IMessageHolder msgs = new MessageHandler();

           ajCompiler.setHolder(msgs);


           // Build up your compiler switches and arguments...
           ArrayList argsList = new ArrayList();

           argsList.add("-inpath");

           argsList.add("c:\dev\foo.jar");

           argsList.add("-outjar");

           argsList.add("c:\dev\outputs\foo-woven.jar");

           argsList.add("-classpath");

           argsList.add("c:\dev\jars\A.jar;c:\dev\B.jar");

           
           // ...and then put them into an array of strings  

           String[] argArray = (String[]) argsList.toArray(new String[]{});


           // Run the compiler

           ajCompiler.runMain(argArray, false);


           // Now get any messages out of the IMessageHolder

           if ( msgs.numMessages(IMessage.WARNING, true) > 0 )
           {

               IMessage[] problems =

                   msgs.getMessages(IMessage.WARNING, true);


               // Now just process the messages ....

              for (int i=0 ; i<problemMessages.length ;i++)

               {

                   ISourceLocation s = problemMessages[i].getSourceLocation();  
                   .. etc ... etc ...


               }// end for
           }// end if



Hope this helps (and that the code formatting doesn't get messed up in transit).


Best regards,

George

________________________________________
George C. Harley



"Sirrurg" <sirrurg@xxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

10/12/2004 08:15

Please respond to
aspectj-users@xxxxxxxxxxx

To
<aspectj-users@xxxxxxxxxxx>
cc
Subject
[aspectj-users] running compiler in java application







Hi,

 

does anyone know, if there is a possibility to run "ajc" directly within an other Java application?

 

Cheers,

   Sir


Back to the top