プロジェクトにカスタム 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 は、作業中のプロジェクトに属するクラスです。
問題をグーグルで検索しようとしましたが、見つけた解決策はどれもうまくいきませんでした。System Scope を使用して、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 にあることを確認しました