2016-10-31 62 views
0

我正在使用勺子在註釋類上生成代碼,所以我可以減少我正在處理的項目的樣板和代碼重複。- 預編譯標誌應該做什麼?

由於該項目是非常小的我一直在尋找途徑,所以我不必整個事情分成已到,爲了進行編譯,所以我AnnotationProcessor兩個甚至三個不同的項目可在

看着the Spoon documentation我發現了--precompile這個標誌,據我瞭解,它應該預編譯整個源代碼並將其添加到類路徑中,所以Spoon將在運行時找到處理器和其他東西。

但是根據我在運行時得到的錯誤,它似乎沒有工作,即使添加了該選項,我仍然錯過了處理器。


[INFO] --- exec-maven-plugin:1.5.0:java (execute-spoon) @ JHTML5 --- 
12:29:50.454 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - output: spooned 
12:29:50.456 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - destination: C:\Data\CrumbleWorks_java\JHTML5\spooned-classes 
12:29:50.457 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - source classpath: null 
12:29:50.457 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - template classpath: [] 
12:29:50.466 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - output: spooned 
12:29:50.466 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - destination: C:\Data\CrumbleWorks_java\JHTML5\spooned-classes 
12:29:50.466 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - source classpath: null 
12:29:50.467 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - template classpath: [] 
12:29:50.467 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - compiling sources: [] 
12:29:50.539 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - compile args: [-encoding, UTF-8, -cp, .;/C:/Data/CrumbleWorks_java/JHTML5/target/classes;/C:/Data/Maven/repo/fr/inria/gforge/spoon/spoon-core/5.4.0/spoon-core-5.4.0.jar;/C:/Data/Maven/repo/org/eclipse/jdt/org.eclipse.jdt.core/3.12.0.v20160516-2131/org.eclipse.jdt.core-3.12.0.v20160516-2131.jar;/C:/Data/Maven/repo/com/martiansoftware/jsap/2.1/jsap-2.1.jar;/C:/Data/Maven/repo/commons-io/commons-io/1.4/commons-io-1.4.jar;/C:/Data/Maven/repo/org/slf4j/log4j-over-slf4j/1.7.21/log4j-over-slf4j-1.7.21.jar;/C:/Data/Maven/repo/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar;/C:/Data/Maven/repo/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar;/C:/Data/Maven/repo/org/crumbleworks/forge/crumbutil/crumbutil/0.1.0/crumbutil-0.1.0.jar;/C:/Data/Maven/repo/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar, -d, C:\Data\CrumbleWorks_java\JHTML5\spooned-classes, -1.8, -proc:none, -preserveAllLocals, -noExit, -enableJavadoc, .] 
12:29:50.790 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - compiled in 323 ms 
12:29:50.792 [spoon.Launcher.main()] INFO spoon.support.StandardEnvironment - Spoon version 5.4.0 
12:29:50.792 [spoon.Launcher.main()] INFO spoon.support.StandardEnvironment - running Spoon... 
12:29:50.792 [spoon.Launcher.main()] INFO spoon.support.StandardEnvironment - start processing... 
12:29:50.792 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - building sources: [] 
12:29:50.792 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - built in 0 ms 
12:29:50.792 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - building templates: [] 
12:29:50.792 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - built in 0 ms 
12:29:50.793 [spoon.Launcher.main()] DEBUG spoon.support.StandardEnvironment - model built in 1 
[WARNING] 
java.lang.reflect.InvocationTargetException 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:498) 
     at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: spoon.SpoonException: Unable to load processor "org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor" - Check your classpath. Did you use the --precompile option? 
     at spoon.support.QueueProcessingManager.addProcessor(QueueProcessingManager.java:79) 
     at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.instantiateAndProcess(JDTBasedSpoonCompiler.java:169) 
     at spoon.Launcher.process(Launcher.java:719) 
     at spoon.Launcher.run(Launcher.java:665) 
     at spoon.Launcher.run(Launcher.java:106) 
     at spoon.Launcher.main(Launcher.java:99) 
     ... 6 more 
Caused by: java.lang.ClassNotFoundException: org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
     at spoon.support.QueueProcessingManager.addProcessor(QueueProcessingManager.java:77) 
     ... 11 more 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.202 s 
[INFO] Finished at: 2016-10-31T12:29:50+01:00 
[INFO] Final Memory: 14M/284M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (execute-spoon) on project JHTML5: An exception occured while executing the Java class. null: InvocationTargetException: Unable to load processor "org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor" - Check your classpath. Did you use the --precompile option? -> [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/MojoExecutionException 

全Maven的錯誤輸出

唉這條線是什麼讓我困惑...

Caused by: spoon.SpoonException: Unable to load processor "org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor" - Check your classpath. Did you use the --precompile option? 

...因爲是的,我沒有使用 - 預編譯選項。感謝您詢問


<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>${exec-plugin.version}</version> 
    <executions> 
     <execution> 
      <id>execute-spoon</id> 
      <phase>process-sources</phase> 
      <goals> 
       <goal>java</goal> 
      </goals> 
      <configuration> 
       <classpathScope>compile</classpathScope> 
       <mainClass>spoon.Launcher</mainClass> 
       <arguments> 
        <argument>--with-imports</argument> 
        <argument>--processors</argument> 
        <argument>org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor</argument> 
        <argument>--enable-comments</argument> 
        <argument>--precompile</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Maven插件聲明使用EXEC-Maven的插件(它執行任何Java可執行文件)


所以運行勺子:什麼是 - 預編譯標誌應該做什麼?
分別是我做錯了什麼?


編輯
這裏有一個Maven的POM並說明如何在不使用maven運行並顯示自述一個簡單的例子:https://github.com/CrumbleWorks/Spoon-Precompile-Issue

+0

是org.crumbleworks.forge.jhtml5.spoon.AttributeProcessor.class在類路徑? –

+0

@MartinMonperrus它是正在編譯的代碼的一部分 –

+0

@MartinMonperrus我已經添加了一個演示問題的示例項目 –

回答

0

--precompile選項編譯提供的源代碼作爲輸入,因此對於所有CtTypeReference對象,可以使用getActualClass()獲得實際的類。此外,它還可以使getActualClass()適用於任何 CtType

(這允許在同一個分析或改造與Java的反射混合勺的反射)

相關問題