项目抛出多个编译错误异常

时间:2014-08-29 09:48:19

标签: java spring groovy intellij-idea spring-boot

我使用spring.io指南中的gradle构建文件,使用intellij 13.0.1在ubuntu上选择了一个spring-boot项目。我在/ opt文件夹中有一些groovy和gradle,但切换到gvm所以我当前的groovy是:

joseph@do-enr-pc-2:~$ groovy --version
Groovy Version: 2.3.6 JVM: 1.8.0_20 Vendor: Oracle Corporation OS: Linux
joseph@do-enr-pc-2:~$ echo $GROOVY_HOME
/home/joseph/.gvm/groovy/current

这是一个简单的项目来测试它的样子。所有需要的文件都在pastie.org

当我用java运行我的项目时,我得到以下内容:

joseph@do-enr-pc-2:/home/joseph/micro-smpp-client-java$ ./gradlew springBoot && java build/libs/micro-smpp-client-0.1.0.jar --stacktrace
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "mainClass" on "task ':springBoot'", value: "net.myproject.smpp...".
:springBoot UP-TO-DATE                     

 BUILD SUCCESSFUL

 Total time: 2.813 secs
 Error: Could not find or load main class build.libs.micro-smpp-client-0.1.0.jar

但是当我用groovy运行时,我有以下内容:

 joseph@do-enr-pc-2:/home/joseph/micro-smpp-client-java$ ./gradlew springBoot && groovy build/libs/micro-smpp-client-0.1.0.jar --stacktrace
 Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
 Deprecated dynamic property: "mainClass" on "task ':springBoot'", value: "net.myproject.smpp...".
 :springBoot UP-TO-DATE                     

 BUILD SUCCESSFUL

 Total time: 3.934 secs
 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
 /home/joseph/micro-smpp-client-java/build/libs/micro-smpp-client-0.1.0.jar: 1: unexpected char: 0x5 @ line 1, column 3.
 PK
 ^

 1 error

根据我的理解,一些.class显然已经出现在我的springBoot执行生成的可能之前,所以我将Application.groovy重命名为AppStarter.groovy,但它没有任何区别。

如何解决这个问题,谢谢!!

编辑应用@Dave Syer的建议

在下面运行./gradlew bootRun之后

是我的输出:

 Deprecated dynamic property: "mainClass" on "task ':springBoot'", value:  "net.myproject.smpp.client...".    
:compileJava UP-TO-DATE                    
:compileGroovy UP-TO-DATE      
:processResources UP-TO-DATE      
:classes UP-TO-DATE      
:findMainClass                 
:bootRun FAILED 

:bootRun FAILED                                     

 FAILURE: Build failed with an exception.

 * What went wrong:
 Execution failed for task ':bootRun'.
 > No main class specified

 * Try:         
 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

运行/gradlew build && java -jar build/libs/*.jar后,这就是我得到的:

 Deprecated dynamic property: "mainClass" on "task ':springBoot'", value:  "net.myproject.smpp.client...".
 :compileJava UP-TO-DATE                    
 :compileGroovy UP-TO-DATE     
 :processResources UP-TO-DATE      
 :classes UP-TO-DATE      
 :jar                 
 :bootRepackage FAILED          

  FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':bootRepackage'.
  > Unable to find main class

  * Try:        
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

1 个答案:

答案 0 :(得分:2)

我认为你的“springBoot”任务实际上并没有做任何事情(它是空的)。可能你打算这样做?

springBoot {
   mainClass = "net.myproject.smpp.client.Application"
}

配置Spring Boot插件,然后

$ ./gradlew bootRun

$ ./gradlew build && java -jar build/libs/*.jar

构建一个jar并运行它。

编辑:并确保你的主类不在默认包中(如果你做得对,你甚至不需要在springBoot闭包中声明它,只要你的应用程序中只有一个主类)。