Bug 450636 - Make ajc automatically add aspectjrt.jar to classpath if necessary
Summary: Make ajc automatically add aspectjrt.jar to classpath if necessary
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.4   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-08 07:37 EST by Alexander Kriegisch CLA
Modified: 2014-11-08 07:37 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kriegisch CLA 2014-11-08 07:37:28 EST
Whenever aspectjrt*.jar is not explicitly put onto the classpath by users of ajc, compilation fails with this error:

[error] classpath error: unable to find org.aspectj.lang.JoinPoint (check that aspectjrt.jar is in your classpath)

The batch scripts for UNIX and Windows both set ASPECTJ_HOME, if not present. So I think that ajc itself (not the batch files) could be made a bit smarter by searching for 

$ASPECTJ_HOME/lib/aspectjrt*.jar

on the file system (I used the "*" because there might be a version number attached, who knows?) and adding it to the end of the classpath - either always or just in case it catches an error about unfound classes from org.aspectj.lang..*. Always would not hurt, I guess, even if ajc is just used as a replacement for java or ejc and no aspects are involved. But in order to avoid side effects it might make sense to be a bit more careful there.

I tried adding something like this to my ajc.bat on Windows:

if "%CLASSPATH%" == "" set CLASSPATH=%ASPECTJ_HOME%\lib\aspectjrt.jar

This only works as long as the user does not specify any "-cp my_path" parameters by himself because as soon as he does, %CLASSPATH% is completely overridden. The user could use "-cp %CLASSPATH%;my_path" in that case, but that would need to be documented (at the moment all samples set CLASSPATH with aspectjrt.jar on it manually). Even though with some platform-dependent shell magic the classpath could be smartly manipulated to user-specified concatenate "-cp" and/or "-classpath" parameters and %CLASSPATH%, this would be complicated. I think that it makes more sense to do that in ajc's main class.