我在 one 上实现了 Gradle我的项目。我将 Netbeans 8.02 与 gradle 插件一起使用。
结构应该是这样的,源码在jgli/src/main/java/
下,资源在jgli/src/main/resources/
下
主类是jgli/src/main/java/test/Main.java
如果我通过 ide 运行它,它会在 Windows 上运行,它 crashes在 Linux 上。这就是我现在尝试通过控制台运行它的原因:
java -jar jgli.jar
但我不断得到:
Error could not find or load main class '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
部分并添加了 manifest 部分。
我尝试将 'test.Main'
添加到 ext.mainClass,但它什么也没改变..
Here你可以下载 jar。
这是我的MANIFEST.MF
:
Manifest-Version: 1.0
Main-Class: test.Main
Main.class 位于 jar 中。
Main.java 有包声明 package test;
也试过
apply plugin: 'application'
mainClassName = 'test.Main'
没有成功..
我错过了什么?
最佳答案
我刚找到你的 git repository和你的来源 Main class ,似乎它实现了一些接口(interface),该接口(interface)在您的依赖项中提供:
import com.jogamp.newt.event.KeyListener;
import com.jogamp.opengl.util.GLEventListener;
public class Main implements GLEventListener, KeyListener {
...
哪些来自您的一些依赖库:
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'
在那种情况下,当您运行主类时,您的依赖项必须在您的类路径中。尝试提供 -cp
选项来指向可以找到依赖项的路径。
关于java - Gradle,错误找不到或加载主类 'test.Main',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33275309/