繁体   English   中英

摇篮,错误找不到或加载主类“ test.Main”

[英]Gradle, error could not find or load main class '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正确位于jar内。 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 {
  ...

这些来自您的一些依赖库:

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构建

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM