我想在我的项目中添加一个自定义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是一个属于我正在处理的项目的类。
我试图谷歌解决这个问题,但我找不到任何解决方案。我可以使用系统范围并通过
给出jar的位置<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中
答案 0 :(得分:0)