STS(eclipse)からmavenビルドでjarファイルを作ろうとしたらエラーになった話
事象
STS(eclipse)からmavenビルドでjarファイルを作成しようとしたらエラーが起きたので行った対処
余談ですが、jarファイルを作成する方法は、
プロジェクト右クリック→「実行」→「maven ビルド…」で「構成の編集」を開き、
ゴールにclean dependency:copy-dependencies -DoutputDirectory=lib packageを指定する。
(こうすることでアプリのjar以外に、依存するjarファイルもtargetディレクトリの中に一式作成される)
1.
エラー内容
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Blank Project 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for batch:MultiStructure-child1:jar:1.0-SNAPSHOT is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.966 s [INFO] Finished at: 2018-01-23T11:35:18+09:00 [INFO] Final Memory: 8M/20M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project batch: Could not resolve dependencies for project batch:batch:jar:1.0.0-SNAPSHOT: Failure to find batch:MultiStructure-child1:jar:1.0-SNAPSHOT in http://repo.terasoluna.org/nexus/content/repositories/terasoluna-batch-snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of terasoluna-batch-snapshots has elapsed or updates are forced -> [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/DependencyResolutionException
原因
mavenでブランクプロジェクトを作成した時のプロジェクト名を後から変更していたため、
pom.xmlのプロジェクト名の修正漏れが発生していた。
(元々は「MultiStructure-child1」という子プロジェクトがいたのだが、名前をあとから変更していた。)
解決策
マルチプロジェクト構成の場合、親と子のpom.xml上で
プロジェクト名を更新する。(書き換える)
2.
事象
1のエラー対処後・・・
エラー内容
[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Child module C:\MultiStructure\MultiStructure-parent\batch-env of C:\MultiStructure\MultiStructure-parent\pom.xml does not exist @ [ERROR] Child module C:\MultiStructure\MultiStructure-parent\batch-app of C:\MultiStructure\MultiStructure-parent\pom.xml does not exist @ @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project batch:batch:1.0-SNAPSHOT (C:\MultiStructure\MultiStructure-parent\pom.xml) has 2 errors [ERROR] Child module C:\MultiStructure\MultiStructure-parent\batch-env of C:\MultiStructure\MultiStructure-parent\pom.xml does not exist [ERROR] Child module C:\MultiStructure\MultiStructure-parent\batch-app of C:\MultiStructure\MultiStructure-parent\pom.xml does not exist [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/ProjectBuildingException
原因
フォルダ名も変えてなかった。
解決策
.m2のリポジトリ内の対象プロジェクトのディレクトリを消して再度実行。
(mavenでブランクプロジェクトを作成すると、.m2リポジトリの中に対応するプロジェクトのディレクトリが作成される。)
3.
事象
2のエラー対処後・・・
エラー内容
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Blank Project 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for batch:batch-env:jar:1.0-SNAPSHOT is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.170 s [INFO] Finished at: 2018-01-23T13:57:00+09:00 [INFO] Final Memory: 8M/20M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project batch-app: Could not resolve dependencies for project batch:batch-app:jar:1.0.0-SNAPSHOT: Failure to find batch:batch-env:jar:1.0-SNAPSHOT in http://repo.org/nexus/content/repositories/batch-snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of batch-snapshots has elapsed or updates are forced -> [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/DependencyResolutionException
原因
.m2リポジトリ上に存在しないものをプロジェクトのpom.xmlでdependencyしていた。
つまり、マルチプロジェクト構成の場合はアプリケーション(app)と環境設定(env)を別々のプロジェクトで分けているため、
appからenvのjarをdependencyしており、それが.m2リポジトリ上に存在しないと怒られていた。
解決策
dependencyから外すか、先にenvプロジェクトのjarを作成しそいつをリポジトリに格納するか参照ライブラリーとして読み込ませるとかする。
(追記:親プロジェクトでビルドしたらdependencyしたままでもビルドできるぽい・・?)
4.
事象
3の対処後・・・
エラー内容
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Blank Project 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ batch-app --- [INFO] Deleting C:\MultiStructure\batch\batch-app\target [INFO] [INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ batch-app --- [INFO] Copying junit-3.8.1.jar to C:\MultiStructure\batch\batch-app\lib\junit-3.8.1.jar [INFO] Copying batch-5.0.0.RELEASE.jar to C:\MultiStructure\batch\batch-app\lib\batch-5.0.0.RELEASE.jar [INFO] jettison-1.2.jar already exists in destination. [INFO] mybatis-typehandlers-jsr310-1.0.2.jar already exists in destination. [INFO] slf4j-api-1.7.22.jar already exists in destination. [INFO] logback-core-1.1.8.jar already exists in destination. [INFO] h2-1.4.193.jar already exists in destination. [INFO] spring-batch-core-3.0.7.RELEASE.jar already exists in destination. [INFO] commons-dbcp2-2.1.1.jar already exists in destination. [INFO] hibernate-validator-5.2.4.Final.jar already exists in destination. [INFO] javax.batch-api-1.0.1.jar already exists in destination. [INFO] spring-aop-4.3.5.RELEASE.jar already exists in destination. [INFO] jcl-over-slf4j-1.7.22.jar already exists in destination. [INFO] xpp3_min-1.1.4c.jar already exists in destination. [INFO] spring-retry-1.1.5.RELEASE.jar already exists in destination. [INFO] logback-classic-1.1.8.jar already exists in destination. [INFO] postgresql-9.4.1212.jre7.jar already exists in destination. [INFO] mybatis-spring-1.3.1.jar already exists in destination. [INFO] spring-beans-4.3.5.RELEASE.jar already exists in destination. [INFO] xmlpull-1.1.3.1.jar already exists in destination. [INFO] xstream-1.4.9.jar already exists in destination. [INFO] spring-batch-infrastructure-3.0.7.RELEASE.jar already exists in destination. [INFO] javax.inject-1.jar already exists in destination. [INFO] spring-expression-4.3.5.RELEASE.jar already exists in destination. [INFO] mybatis-3.4.2.jar already exists in destination. [INFO] javax.el-3.0.0.jar already exists in destination. [INFO] spring-context-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-core-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-tx-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-jdbc-4.3.5.RELEASE.jar already exists in destination. [INFO] com.ibm.jbatch-tck-spi-1.0.jar already exists in destination. [INFO] db2jcc4-10.1.jar already exists in destination. [INFO] validation-api-1.1.0.Final.jar already exists in destination. [INFO] classmate-1.3.3.jar already exists in destination. [INFO] commons-pool2-2.4.2.jar already exists in destination. [INFO] lombok-1.16.12.jar already exists in destination. [INFO] jboss-logging-3.3.0.Final.jar already exists in destination. [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ batch-app --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 19 resources [INFO] [INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ batch-app --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 16 source files to C:\MultiStructure\batch\batch-app\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.335 s [INFO] Finished at: 2018-01-23T14:06:20+09:00 [INFO] Final Memory: 13M/32M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project batch-app: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [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
原因
ビルドに使っていたのはJDKじゃなくてJREになっていた。
解決策
JREをJDKに変更する(環境変数JAVA_HOMEで指定しているjavaのランタイム環境を変更する。)
参照
5.
事象
4の対処後・・・
エラー内容
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Blank Project 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ batch-app --- [INFO] Deleting C:\MultiStructure\batch\batch-app\target [INFO] [INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ batch-app --- [INFO] jettison-1.2.jar already exists in destination. [INFO] mybatis-typehandlers-jsr310-1.0.2.jar already exists in destination. [INFO] slf4j-api-1.7.22.jar already exists in destination. [INFO] logback-core-1.1.8.jar already exists in destination. [INFO] h2-1.4.193.jar already exists in destination. [INFO] spring-batch-core-3.0.7.RELEASE.jar already exists in destination. [INFO] commons-dbcp2-2.1.1.jar already exists in destination. [INFO] hibernate-validator-5.2.4.Final.jar already exists in destination. [INFO] javax.batch-api-1.0.1.jar already exists in destination. [INFO] spring-aop-4.3.5.RELEASE.jar already exists in destination. [INFO] jcl-over-slf4j-1.7.22.jar already exists in destination. [INFO] xpp3_min-1.1.4c.jar already exists in destination. [INFO] junit-3.8.1.jar already exists in destination. [INFO] spring-retry-1.1.5.RELEASE.jar already exists in destination. [INFO] logback-classic-1.1.8.jar already exists in destination. [INFO] postgresql-9.4.1212.jre7.jar already exists in destination. [INFO] mybatis-spring-1.3.1.jar already exists in destination. [INFO] spring-beans-4.3.5.RELEASE.jar already exists in destination. [INFO] xmlpull-1.1.3.1.jar already exists in destination. [INFO] xstream-1.4.9.jar already exists in destination. [INFO] spring-batch-infrastructure-3.0.7.RELEASE.jar already exists in destination. [INFO] javax.inject-1.jar already exists in destination. [INFO] spring-expression-4.3.5.RELEASE.jar already exists in destination. [INFO] mybatis-3.4.2.jar already exists in destination. [INFO] javax.el-3.0.0.jar already exists in destination. [INFO] spring-context-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-core-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-tx-4.3.5.RELEASE.jar already exists in destination. [INFO] spring-jdbc-4.3.5.RELEASE.jar already exists in destination. [INFO] com.ibm.jbatch-tck-spi-1.0.jar already exists in destination. [INFO] db2jcc4-10.1.jar already exists in destination. [INFO] validation-api-1.1.0.Final.jar already exists in destination. [INFO] classmate-1.3.3.jar already exists in destination. [INFO] commons-pool2-2.4.2.jar already exists in destination. [INFO] lombok-1.16.12.jar already exists in destination. [INFO] jboss-logging-3.3.0.Final.jar already exists in destination. [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ batch-app --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 19 resources [INFO] [INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ batch-app --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 16 source files to C:\MultiStructure\batch\batch-app\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[12,28] パッケージhoge.xmlは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[13,35] パッケージhoge.xml.commonは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[14,38] パッケージhoge.xml.datatypesは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[15,38] パッケージhoge.xml.datatypesは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[132,13] シンボルを見つけられません シンボル: クラス hogehoge 場所: クラス service.sample03.Sample03JobServiceImpl [INFO] 5 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.990 s [INFO] Finished at: 2018-01-23T14:56:55+09:00 [INFO] Final Memory: 18M/47M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project batch-app: Compilation failure: Compilation failure: [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[12,28] パッケージhoge.xmlは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[13,35] パッケージhoge.xml.commonは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[14,38] パッケージhoge.xml.datatypesは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[15,38] パッケージhoge.xml.datatypesは存在しません [ERROR] /C:/MultiStructure/batch/batch-app/src/main/java/service/sample03/Sample03JobServiceImpl.java:[132,13] シンボルを見つけられません [ERROR] シンボル: クラス hogehoge [ERROR] 場所: クラス service.sample03.Sample03JobServiceImpl [ERROR] -> [Help 1] [ERROR]
原因
hogehogeクラスをmavenから持ってこれなかったため。
今回hogehogeクラスは自前で作成したやつで、mavenのセントラルリポジトリには当然ないのであるため自分でリポジトリに登録してやる必要があった。
解決策
コマンドプロンプトから、mvnコマンドを使ってリポジトリにローカルでjarの登録を行う。
jarのあるディレクトリ上で以下のコマンドをたたく。
(-Dfile=C:\xxx\hoge.jarみたいな絶対指定でもいい)
mvn install:install-file ^ -Dfile=hoge.jar ^ -DgroupId=hoge.hoge ^ -DartifactId=hoge ^ -Dversion=1.0 ^ -Dpackaging=jar ^ -DgeneratePom=true
その後、無事ビルド成功しました。
長かった・・・!