2009-08-06 109 views
6

我正在嘗試m2eclipse,Maven的Eclipse插件,並且已經注意到資源現在被排除在我所有項目的構建路徑之外。爲什麼m2eclipse從Eclipse構建路徑中排除資源?

我見過a question on the M2Eclipse FAQ page似乎處理這個確切的問題,但答案(釋義)似乎是說,這是故意允許資源過濾,一切都應該工作。

但是,當我在Eclipse中運行我的應用程序時,依賴項目中的大量資源無法通過我的應用程序找到。

我已經嘗試過我平時的Eclipse揮手 - 橡皮雞行動(清理所有項目,以 - 清潔開始)無濟於事。我確定我錯過了一些相當簡單的事情。有沒有人有什麼建議?

編輯:在m2控制檯中進行了一些挖掘,發現其中一個項目的構建不正確。當它試圖在用於構建其中一個項目的自定義插件中查找org.apache.maven.plugin.MojoFailureException時,我得到一個ClassNotFoundException

 
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the plugin manager executing goal 'ourdemain:ourcustomplugin:2.0:process': Mojo execution failed. 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:505) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149) 
    at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223) 
    at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1) 
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904) 
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304) 
    at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1) 
    at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant$1.execute(DefaultBuildParticipant.java:130) 
    at org.maven.ide.eclipse.internal.project.MavenProjectManagerImpl.execute(MavenProjectManagerImpl.java:986) 
    at org.maven.ide.eclipse.internal.project.MavenProjectFacade.execute(MavenProjectFacade.java:320) 
    at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.executePostBuild(DefaultBuildParticipant.java:116) 
    at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.build(DefaultBuildParticipant.java:80) 
    at org.maven.ide.eclipse.internal.builder.MavenBuilder.build(MavenBuilder.java:84) 
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633) 
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) 
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170) 
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201) 
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253) 
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) 
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256) 
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309) 
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341) 
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140) 
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238) 
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) 
Caused by: org.apache.maven.plugin.PluginExecutionException: Mojo execution failed. 
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:601) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498) 
    ... 27 more 
Caused by: org.apache.maven.plugin.MojoExecutionException: org/apache/maven/plugin/MojoFailureException 
    at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:98) 
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579) 
    ... 28 more 
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/plugin/MojoFailureException 
    at java.lang.Class.getDeclaredConstructors0(Native Method) 
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) 
    at java.lang.Class.getConstructor0(Class.java:2699) 
    at java.lang.Class.getConstructor(Class.java:1657) 
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:587) 
    at org.jruby.javasupport.Java.new_proxy_instance(Java.java:570) 
    at org.jruby.javasupport.JavaInvokerSnew_proxy_instancexx1.call(Unknown Source) 
    at org.jruby.runtime.callback.InvocationCallback.execute(InvocationCallback.java:49) 
    at org.jruby.internal.runtime.methods.FullFunctionCallbackMethod.internalCall(FullFunctionCallbackMethod.java:79) 
    at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79) 
    at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:577) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206) 
    at org.jruby.evaluator.EvaluationState.setupArgs(EvaluationState.java:2182) 
    at org.jruby.evaluator.EvaluationState.attrAssignNode(EvaluationState.java:481) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:191) 
    at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200) 
    at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163) 
    at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167) 
    at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79) 
    at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125) 
    at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:564) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206) 
    at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:544) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206) 
    at org.jruby.evaluator.EvaluationState.localAsgnNode(EvaluationState.java:1230) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:285) 
    at org.jruby.evaluator.EvaluationState.rescueNode(EvaluationState.java:1522) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:349) 
    at org.jruby.evaluator.EvaluationState.ensureNode(EvaluationState.java:980) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:246) 
    at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163) 
    at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167) 
    at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79) 
    at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125) 
    at org.jruby.evaluator.EvaluationState.fCallNode(EvaluationState.java:1019) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:252) 
    at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200) 
    at org.jruby.evaluator.EvaluationState.rootNode(EvaluationState.java:1622) 
    at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:355) 
    at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163) 
    at org.jruby.Ruby.eval(Ruby.java:274) 
    at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.runInterpreter(JRubyRuntimeInvoker.java:392) 
    at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.invoke(JRubyRuntimeInvoker.java:313) 
    at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:81) 
    ... 29 more 
Caused by: java.lang.ClassNotFoundException: org.apache.maven.plugin.MojoFailureException 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251) 
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) 
    ... 75 more 

回答

5

在常見問題中提到的資源過濾運行。在實踐中,我發現這比Maven構建器的運行速度慢得多,而且只有在配置時纔會運行(默認情況下僅在完整版本中),這讓您不知所措,不知道爲什麼變化沒有拿起。

我傾向於修改Eclipse類路徑以包含src/main/resources。這對大多數用例來說已經足夠了。

對於簡單的方法不起作用的情況(例如,如果一個依賴項目有一些複雜的資源處理),我按照Robert的建議做,並關閉工作區解析,然後將依賴項安裝到本地存儲庫,包含在Maven類路徑容器中。

3

嘗試在嵌入式(3.0 AFAIK)Maven運行時和用於執行構建(本地安裝)的運行時之間切換。每當Maven的助洗劑對項目運行

Maven installations http://img150.imageshack.us/img150/6193/m2eclipseinstallations.png

+0

感謝您的建議 - 我已經嘗試過這一點,它沒有任何區別。 – 2009-08-06 08:46:06

+1

您是否嘗試過關閉工作區分辨率?然後,您將根據存儲庫中已安裝的工件構建每個項目。 – 2009-08-06 08:58:06