Gradle,错误找不到或加载主类'test.Main'
我在我的一个项目上实施了Gradle。 我使用Netbeans 8.02和gradle插件。
  结构是理所应当的,源位于下jgli/src/main/java/下资源jgli/src/main/resources/ 
  Main类是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正确地位于罐子里面。  Main.java具有包声明package test; 
试过也
apply plugin: 'application'
mainClassName = 'test.Main'
没有成功..
我错过了什么?
我刚刚找到了你的git仓库和你的Main类的源代码,似乎它实现了一些在你的依赖关系中提供的接口:
import com.jogamp.newt.event.KeyListener;
import com.jogamp.opengl.util.GLEventListener;
public class Main implements GLEventListener, KeyListener {
  ...
哪些来自你的一些依赖libs:
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'
  在这种情况下,当您运行Main类时,您的依赖项必须位于您的类路径中。  尝试提供-cp选项以指向可找到依赖关系的路径。 
通常,您在构建文件中设置主类,如下所示:
mainClassName = 'package.MainClassName'
你把它作为参数传递吗? - > hasProperty然后你必须运行你的构建,如:gradle -PmainClass = MyClass构建
链接地址: http://www.djcxy.com/p/88521.html上一篇: Gradle, error could not find or load main class 'test.Main'
下一篇: Oauth suddenly not working on iphone (with FS app installed only)
