我在一个项目中实现了Gradle。我使用带有Gradle插件的Netbeans 8.02。
结构应该是正确的,源代码位于
主类是
结构应该是正确的,源代码位于
jgli/src/main/java/
下,资源位于jgli/src/main/resources/
下。主类是
jgli/src/main/java/test/Main.java
如果我通过IDE运行它,在Windows上运行良好,在Linux上会崩溃。这就是为什么我现在尝试通过控制台运行它:
java -jar jgli.jar
但我一直得到以下错误:
这是我的错误:找不到或无法加载主类“test.Main”
build.gradle
。apply plugin: 'java'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
// NetBeans will automatically add "run" and "debug" tasks relying on the
// "mainClass" property. You may however define the property prior executing
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
//
// Note however, that you may define your own "run" and "debug" task if you
// prefer. In this case NetBeans will not add these tasks but you may rely on
// your own implementation.
if (!hasProperty('mainClass')) {
ext.mainClass = ''
}
repositories {
mavenCentral()
// You may define additional repositories, or even remove "mavenCentral()".
// Read more about repositories here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
}
dependencies {
// TODO: Add dependencies here ...
// You can read more about how to add dependency here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
testCompile group: 'junit', name: 'junit', version: '4.10'
compile 'org.jogamp.jogl:jogl-all-main:2.3.2'
compile 'org.jogamp.jogl:nativewindow-main:2.3.2'
compile 'org.jogamp.jogl:newt-main:2.3.2'
compile 'org.jogamp.gluegen:gluegen-rt-main:2.3.2'
}
jar {
manifest {
attributes 'Main-Class': 'test.Main'
}
}
我刚刚修改了dependecies
部分并添加了清单部分。
我尝试将'test.Main'
添加到ext.mainClass中,但没有任何变化..
这里你可以下载jar包。
这是我的MANIFEST.MF
:
Manifest-Version: 1.0
Main-Class: test.Main
Main.class位于jar包中的正确位置。
Main.java有包声明package test;
也尝试过
apply plugin: 'application'
mainClassName = 'test.Main'
没有成功...
我错过了什么?
package test;
。如果没有它,类将无法找到。 - Stanislav