solved LibGDX package set up

When I create a LibGDX project, you create that first package in the core directory, usually starting with com.xxxx. Do all subsequent packages need to go in that package? I’m asking because I’m getting an error when I do a build with gradle (cannot find main class DesktopLauncher), but I wanted to know this answer before I changed everything around. Thanks.

if it helps, here’s my build.gradle file:


apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = ["../android/assets"]

project.ext.mainClassName = "com.mygame.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 debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

task dist(type: Jar) {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    with jar
}


dist.dependsOn classes

eclipse.project.name = appName + "-desktop"

And my java version is:


java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) Client VM (build 25.241-b07, mixed mode, sharing)

Well, does anyone see anything wrong with that Gradle file? I’m absolutely stumped on why the Gradle build passes fine but wont launch because of that error. To my knowledge Gradle is using the same version of java, and in the build path, the main class is indeed DesktopLauncher. Anyone have any ideas on why this is happening?

Edit: I’m a noob with Gradle and it might be something easy and dumb, but if it is I can’t figure it out.

whats the “package” statement in your DesktopLauncher.java file?

Here’s the file:


package com.mygdx.mygame.desktop;

import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.mygame.MyGame;

import helpers.GameAttributeHelper;

/**
 * Launch game on desktop.
 * 
 * @author Fabulous Fellini
 *
 */
public class DesktopLauncher {
	public static void main (String[] arg) {
		LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
		config.addIcon("artwork/logos/GoldenAgeIcon.png", FileType.Internal);
		config.title         = "The Golden Age: Legend of the Seven Swords";
		config.foregroundFPS = GameAttributeHelper.FRAMES_PER_SECOND;

		// Full screen.
		float f       = 1.0f;
		// Phone screen.
		//float f       = 0.5f;

		float width   = LwjglApplicationConfiguration.getDesktopDisplayMode().width;
		float height  = LwjglApplicationConfiguration.getDesktopDisplayMode().height;
		config.width  = (int)(width * f);
		config.height = (int)(height * f);
		new LwjglApplication(new MyGame(), config);
	}
}

Then you mainclass property in the gradle file needs to be
com.mygdx.mygame.desktop.DesktopLauncher.

at least in your first post it misses “mygdx”

Yes! I think that has to be it. I will try when I get a break from work. Thank you!

Ok that worked! Now, it can’t find the images lol. I read that the assets folder has to be a source folder (“used as source” in Eclipse) or else it wont compile, so I changed it to be a source file, but that still didn’t work, getting the same error. It’s pointing to the core/assets folder, so I’m not sure what’s wrong. I’m going to do more investigation into that tonight.

Dammit how do you put the “solved” tag on a post?

Edit: I guess it just needed a second. Solved tag solved.