2

我想在我的项目中添加一个自定义 jar。据我了解,最好的方法是首先将 jar 添加到我的本地存储库,然后将其添加到我的 pom.xml。

所以我尝试了以下方法:

 mvn install:install-file -Dfile=/home/martin/linuxhome/work/libMediator/libMediator
 /dist/libMediator.jar -DgroupId=com.src.libMediator -DartifactId=libMediator 
 Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

然后我将以下内容添加到我的 pom.xml 中:

...
<packaging>war</packaging>
...
<dependencies>
...
<dependency>
    <groupId>com.src.libMediator</groupId>
    <artifactId>libMediator</artifactId>
    <version>1.0</version>
    <scope>runtime</scope>
</dependency>
</dependencies>

不幸的是,我收到以下错误:

[INFO] Scanning for projects...
[INFO]                                                                             
[INFO] ------------------------------------------------------------------------
[INFO] Building Reportgenerator 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for joda-time:joda-time-jsptags:jar:1.0.2 is missing, no dependency information available
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ Reportgenerator ---
[debug] execute contextualize
[INFO] Copying 26 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Reportgenerator ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 21 source files to /home/martin/linuxhome/Dropbox/c/Reportgenerator/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/martin/linuxhome/Dropbox/c/Reportgenerator/src/main/resources/boilerplate/ReportIdentifizierer.java:[8,32] package com.src.libMediator.prod does not exist
[ERROR] /home/martin/linuxhome/Dropbox/c/Reportgenerator/src/main/resources/boilerplate/ReportIdentifizierer.java:[30,19] cannot find symbol
  symbol:   variable C_ProdUtility
  location: class boilerplate.ReportIdentifizierer
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.116s
[INFO] Finished at: Sat Sep 07 15:30:50 CEST 2013
[INFO] Final Memory: 18M/169M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Reportgenerator: Compilation failure:     Compilation failure:
[ERROR] /home/martin/linuxhome/Dropbox/c/Reportgenerator/src/main/resources/boilerplate/ReportIdentifizierer.java:[8,32] package com.src.libMediator.prod does not exist
[ERROR] /home/martin/linuxhome/Dropbox/c/Reportgenerator/src/main/resources/boilerplate/ReportIdentifizierer.java:[30,19] cannot find symbol
[ERROR] symbol:   variable C_ProdUtility
[ERROR] location: class boilerplate.ReportIdentifizierer
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

C_ProdUtility 是我想要包含的 jar 中的一个类,boilerplate.ReportIdentifizierer 是一个属于我正在处理的项目的类。

我试图用谷歌搜索这个问题,但我找到的解决方案都没有奏效。我可以使用系统范围并通过

<systemPath>${project.basedir}/lib/libMediator.jar</systemPath>

. 然后它会编译,但不鼓励这样做,并且在运行时不提供 jar。我还没有找到如何做到这一点。

如果我使用

编译

生成的 .war 给出以下错误消息:

java.lang.ClassNotFoundException: com.src.libMediator.prod.C_ProdUtility from [Module "deployment.Reportgenerator.war:main" from Service Module Loader]

我验证了 com.src.libMediator.prod.C_ProdUtility 在 libMediator.jar

4

1 回答 1

0

消除

<scope>runtime</scope>

通过这样做,您可以更改要编译的范围。如果您对细节感兴趣,请检查范围在文档中的工作方式。

于 2013-09-08T01:06:55.650 回答