我遇到的问题是Java能够找到我的主要类LibGDX游戏。我正和其他人一起工作,所有人都能正确设置项目并在他们的计算机上运行/构建游戏。
项目结构类似于:
love-pirates
core
src
com.pirates.game
LovePirates.java
desktop
src
com.pirates.game.desktop
DesktopLauncher.java
当我尝试运行DesktopLauncher.java时,我得到:
Exception in thread "main" java.lang.ClassNotFoundException: com.pirates.game.desktop.DesktopLauncher
当我尝试通过Gradle构建时,我得到:
error: cannot find symbol
import com.pirates.game.LovePirates;
^
symbol: class LovePirates
location: package com.pirates.game
这是桌面模块中的build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "com.pirates.game.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
eclipse {
project {
name = appName + "-desktop"
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
}
}
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
}
我的核心模块中的build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
即使我作为JAR导出并尝试在另一台机器上运行它,我也会找不到主类。所以它有时可以编译完成(0个警告,0个错误),但是没有正确运行。
我正在使用jdk 1.8.0_65在OSX上使用IntelliJ IDEA 15。我很乐意提供更多所需信息。 非常感谢任何帮助!
编辑0:以下是我编译的DesktopLauncher的路径:
love-pirates/desktop/build/classes/main/com/pirates/game/desktop/DesktopLauncher.class