tanamonの稀に良く書く日記

KEEP CALM AND DRINK BEER

Maven2でEclipse上から実行した場合だけエラーになる場合

コマンドライン上で実行したら成功するのに、なぜかEclipse上で実行するとエラーになるという場合。
プロジェクトの設定のMavenにある、「Resolve dependencies from Workspace projects」(日本語だと「ワークスペース・プロジェクトから依存関係を解決」)のチェックを外すと成功したりします。

ちなみに、一度チェックありの状態でRun Asから実行設定を行うと「Resolve Workspace artifacts」(日本語だと「ワークスペースアーティファクトの解決」)という同様の意味を持つチェックが有効になっているので、こちらも忘れずに変更すること。

エラーメッセージ

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot copy a directory: C:\apps\eclipse3.4\workspace\myproject\war\target\classes; Did you package/install active project artifact:
	artifact = active project artifact:
	artifact = jp.tanamon:myproject-war:war:1.0.5-SNAPSHOT:compile;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml?
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Cannot copy a directory: C:\apps\eclipse3.4\workspace\myproject\war\target\classes; Did you package/install active project artifact:
	artifact = active project artifact:
	artifact = jp.tanamon:myproject-war:war:1.0.5-SNAPSHOT:compile;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml?
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:703)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:540)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:519)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
	at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:41)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot copy a directory: C:\apps\eclipse3.4\workspace\myproject\war\target\classes; Did you package/install active project artifact:
	artifact = active project artifact:
	artifact = jp.tanamon:myproject-war:war:1.0.5-SNAPSHOT:compile;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml;
	project: MavenProject: jp.tanamon:myproject-war:1.0.5-SNAPSHOT @ C:\apps\eclipse3.4\workspace\myproject\war\pom.xml?
	at org.apache.maven.plugin.ear.EarMojo.execute(EarMojo.java:200)
	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:678)
	... 17 more