Having trouble executing my program from a jar, using Jinput

33 views Asked by At

When I run my program from the IDE, it executes as expected and I don't see any errors in the log. The problem occurs when I try to run the artifact jar from the batch file.

I have a run configuration to execute the jar and I also have a windows .bat file. My end goal is to have the bat file execute the program for me.

Here is the source code for the entry point in the application. (launcher.ArcadeLauncher)

package launcher;

import launcher.framework.util.Logger;
import launcher.menu.MenuGame;

import java.io.*;

public class ArcadeLauncher {
    public static final String PROP_LIBRARY_PATH = "net.java.games.input.librarypath";
    public static void main(final String[] args) {

        Logger.info(ArcadeLauncher.class.getSimpleName() + " started.");

        final String libraryPath = new File("src/main/resources/lib").getAbsolutePath();

        System.setProperty(PROP_LIBRARY_PATH, libraryPath);

        System.load(libraryPath + File.separator + "jinput-dx8_64.dll");
        System.load(libraryPath + File.separator + "jinput-raw_64.dll");

        final Thread gameThread = new Thread(new MenuGame());
        gameThread.start();

        try {
            gameThread.join();
        } catch (InterruptedException e) {
            Logger.error(e.getMessage(), e);
        }

        Logger.info(ArcadeLauncher.class.getSimpleName() + " complete.");
    }
}

Relevant project screenshots A screenshot of my project layout Run configuration the works from IDE Run configuration tat suddenly started working.

The batch file I plan to use to execute the jar.

@echo off
Title ArcadeLauncher - No Arguments

REM Set the directories for your libraries and classes
set "LIB_DIR=resources\lib"
set "CLASS_DIR=src\main\java"
set "MAIN_CLASS=launcher.ArcadeLauncher"

REM Create a classpath including the .jar files in the lib directory and the directory containing your compiled .class files
set "CP=%CLASS_DIR%;%LIB_DIR%\*"

REM Run the application
java -cp "%CP%" %MAIN_CLASS%

pause

When the batch file is run I get the following error. (Still not working)

Error: Could not find or load main class launcher.ArcadeLauncher
Caused by: java.lang.ClassNotFoundException: launcher.ArcadeLauncher
Press any key to continue . . .

I was expecting no errors.I'm not sure what I'm doing wrong in the batch file and I suspect it's related to the classpath. I could use some help here.

I tried looking for similar issues on stack overflow, I made extensive use of chat-GPT as well. That got me to where I am now. I would appreciate the assistance./

0

There are 0 answers