maven compile fails because i have a non-maven jar
I have a couple of internal libraries which I haven't/don't know how to add to my local maven repository. I've added them to the project's classpath but my maven-compile fails stating that it can't find the classes in the external jars (as expected):
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project proj: Compilation failure: Compilation failure:
dir\src\main\java\package\MyClass.java:[8,25] package blah does not exist
dir\src\main\java\package\MyClass.java:[9,25] package blah does not exist
dir\src\main\java\package\MyClass.java:[21,12] cannot find symbol
symbol : variable Blah
location: class package.MyClass
dir\src\main\jav开发者_如何转开发a\package\MyClass.java:[28,9] cannot find symbol
symbol : variable Blah
location: class package.MyClass
How do I tell maven about a jar I've sneakily added to my project's classpath so it can use it to compile?
I'm not sure you can access the system classpath without a lot of hackary. You can do one of two other things: a system scope dependency or add it to your local repo.
To use a system dependency, just add an entry for each jar you wish to add. Give them the scope "system" and add a <systemPath>
to each. Something like this.
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
You could then use -D jvm properties if you insist on changing the location and compile time.
Adding them to the local repo is a bit of a pain, but the more long term solution.
精彩评论