0
我用下面的命令來編譯和運行HelloWorld的jar文件,但得到了一個錯誤無法找到或加載主類com.johnathanmarksmith.gradle.HelloWorld
無法找到或加載主類 com.johnathanmarksmith .gradle.HelloWorld
誰能告訴我如何解決它?
mkdir runnablejar
cd runnablejar
mkdir -p src/main/java
mkdir -p src/main/resources
mkdir -p src/test/java
mkdir -p src/test/resources
mkdir -p com/johnathanmarksmith/gradle
vi com/johnathanmarksmith/gradle/HelloWorld.java
(insert)
package com.johnathanmarksmith.gradle;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
vi build.gradle
apply plugin: 'java'
jar {
baseName = 'smith'
version = '1.0'
manifest {
attributes 'Main-Class': 'com.johnathanmarksmith.gradle.HelloWorld' }
}
gradle build
java -jar ./build/libs/smith-1.0.jar
我的構建結果是成功
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
它仍然不起作用。我應該把這個包放在main或main/java下面嗎? –
我的錯誤,它的工作原理!謝謝!! –