tags:

views:

361

answers:

1

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\java\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?

+2  A: 

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.

sblundy
thanks that works fine. the jar exists within the project so i just use `${basedir}/.../jar.jar`
pstanton
+1 on "Adding them to the local repo is a bit of a pain, but the more long term solution" part of the answer. System dependencies are a drain on the portability of a project. You will be much better off maintaining that dependency like you do any other (and deploying it to a published maven repo at some point).
whaley