我正在尝试重新包装log4j,以便可以在Android上使用它。为此,我必须使用openbeans库并将每个java.beans替换为com.googlecode.openbeans

显然这还不够,因为在重新打包通过maven log4j之前,我必须在项目中加入openbeans-1.0.jar

因此,我找到了this方法。

我已经通过以下命令安装了openbeans:

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


我检查了命令的正确执行,检查了以下路径中是否存在.jar(确实存在):

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

然后我编辑了pom.xml文件,添加了:

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


但是,如果我尝试mvn package,则会返回此错误:

[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]


就像install-file没用。

我还使用以下代码尝试了this方法(显然,我在项目根目录中复制了.jar):

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


这里返回的错误是:

[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


我在做什么错了?

最佳答案

即使我仍然不明白为什么,我还是发现执行:

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


并在pom中使用:

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


该代码编译没有错误。但是正如我所说,仍然想知道为什么。

10-05 17:46