Cannot add local jar files in maven project

I’m trying to repackage log4j so I can use it with Android. In order to do so, I have to use openbeans library and replace each java.beans with com.googlecode.openbeans.

Obviously this is not sufficient, since before repacking the through maven log4j I’ve to include openbeans-1.0.jar in the project.

So I’ve found this method.

I’ve installed openbeans through the following command:

mvn install:install-file -Dfile=/home/luca/openbeans-1.0.jar -DgroupId=com.googlecode -DartifactId=openbeans -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

I’ve checked that the correct execution of the command checking if the .jar exists in the following path (and it does):

~/.m2/repository/com/googlecode/openbeans/1.0/openbeans-1.0.jar

Then I edited the pom.xml file adding:

<dependency>
  <groupId>com.googlecode</groupId>
  <artifactId>openbeans</artifactId>
  <version>1.0</version>
</dependency>

But if I try mvn package then this error is returned:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.2:run (rmdir_tests_output) on project log4j: Execution rmdir_tests_output of goal org.apache.maven.plugins:maven-antrun-plugin:1.2:run failed: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.2 or one of its dependencies could not be resolved: Failure to find com.googlecode:openbeans:jar:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

Like the install-file didn’t worked.

I’ve tried also with this method, using the following code (obviously I copied the .jar in the project root dir):

<dependency>
  <groupId>com.googlecode</groupId>
  <artifactId>openbeans</artifactId>
  <version>1.0</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/openbeans-1.0.jar</systemPath>
</dependency>

And here the error returned is:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.1:compile (default-compile) on project log4j: Compilation failure
[ERROR] /home/luca/apache-log4j-1.2.17/src/main/java/org/apache/log4j/config/PropertyGetter.java:[31,21] error: package com.googlecode does not exist

What is wrong in what I’m doing?

Answer

Even if I still don’t understand why, I found out that executing:

mvn install:install-file -Dfile=/home/luca/openbeans-1.0.jar -DgroupId=com.googlecode.openbeans -DartifactId=openbeans -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

And using in pom:

<dependency>
  <groupId>com.googlecode.openbeans</groupId>
  <artifactId>openbeans</artifactId>
  <version>1.0</version>
</dependency>

The code is compiled without error. But as I said, still wondering why.

Leave a Reply

Your email address will not be published. Required fields are marked *