2012-08-16 95 views
0

我試圖編譯附帶的gradle(在樣本/常規/快速啓動目錄)的常規快速啓動的例子。 gradle compileGroovygradle jar successfuly既要完成,但我不能運行任何這些:編譯Groovy類

c:\tmp\quickstart\build\classes\main\org\gradle>java Person 
Exception in thread "main" java.lang.NoClassDefFoundError: Person (wrong name: org/gradle/Person) 
     at java.lang.ClassLoader.defineClass1(Native Method) 
     at java.lang.ClassLoader.defineClassCond(Unknown Source) 
     at java.lang.ClassLoader.defineClass(Unknown Source) 
     at java.security.SecureClassLoader.defineClass(Unknown Source) 
     at java.net.URLClassLoader.defineClass(Unknown Source) 
     at java.net.URLClassLoader.access$000(Unknown Source) 
     at java.net.URLClassLoader$1.run(Unknown Source) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
Could not find the main class: Person. Program will exit. 

c:\tmp\quickstart\build\libs>java -jar quickstart.jar 
Failed to load Main-Class manifest attribute from 
quickstart.jar 

然後我加入清單屬性bulid.gradle

jar { 
    manifest { 
     attributes("Main-Class": "org.gradle.Person") 
    } 
} 

,現在我得到:

c:\tmp\quickstart\build\libs>java -jar quickstart.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject 
     at java.lang.ClassLoader.defineClass1(Native Method) 
     at java.lang.ClassLoader.defineClassCond(Unknown Source) 
     at java.lang.ClassLoader.defineClass(Unknown Source) 
     at java.security.SecureClassLoader.defineClass(Unknown Source) 
     at java.net.URLClassLoader.defineClass(Unknown Source) 
     at java.net.URLClassLoader.access$000(Unknown Source) 
     at java.net.URLClassLoader$1.run(Unknown Source) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject 
     at java.net.URLClassLoader$1.run(Unknown Source) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     ... 12 more 
Could not find the main class: org.gradle.Person. Program will exit. 

如何運行時創建的罐子? (還是我錯過了整點...)

回答

2

在搖籃分佈groovy/quickstart樣本並不意味着直接執行。除其他事項外,Person類沒有一個main方法。把它想象成一個圖書館。