I am trying to run some java code and have encountered a bit of an issue I cannot understand. The java class-loader simply does not "find or load" the files I'm directly pointing to.
The directory is as such
(project dir)\uwu_bot\target\classes\com\alejandro\uwu_bot\Bot.class
I make "classes" my working directory and call
java com.alejandro.uwu_bot.Bot
But I get
Error: Could not find or load main class com.alejandro.uwu_bot.Bot
I even go directly to "alejandro\uwu_bot" and do
java Bot
No dice
What could be going on?
The top answer of this question pointed me to a few Oracle articles documenting the command line tool and the process for finding class files. It didn't give me any other ideas. This post also assured me that the problem did not lie in the class name, and it was some deeper technical trouble.
The code isn't very important, and it is simply the main class to a Discord bot I manage.
Bot.java:
public class Bot extends ListenerAdapter {
/**
* Global instance of the main JDA
*/
public static JDA jda;
public static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(1);
public static final SerialPort PORT = SerialPort.getCommPort("COM3");
public static final ThreadLocalRandom RAND = ThreadLocalRandom.current();
public static void main(String[] args) throws Exception {
System.setProperty("http.agent", "Chrome");
// Open the serial port declared in Reference
if (!PORT.openPort())
System.err.println("(WARNING): port busy!!");
jda = new JDABuilder(AccountType.BOT).setToken(TOKEN).build().awaitReady();
jda.addEventListener(new CommandListener());
jda.addEventListener(new GeneralPurposeListener());
jda.addEventListener(new Bot());
...
As told to do so by the question, I added the -Xdiag option to see further verbose output. And it says:
Error: Could not find or load main class Bot
java.lang.NoClassDefFoundError: Bot (wrong name: com/alejandro/uwu_bot/Bot)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Which states directly that it can't find the file
Then I go further out to the "classes" directory and run
java -Xdiag com.alejandro.uwu_bot.Bot
Getting
java.lang.ClassNotFoundException: com.alejandro.uwu_bot.Bot
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Which says the class doesn't exist at all.
EDIT: This has been declared a duplicate, but I beg to differ. I specifically said I tried the solutions on that post and none worked, it's something else. I'm missing something, or that question didn't explain a specific detail I need. Keep In mind I'm not the most experienced in Java.
The file's source tree is as simple as this:
src
├───main
│ └───java
│ └───com
│ └───alejandro
│ └───uwu_bot
│ └───Bot.class
└───test
Multiple files omitted, but these are all that matter right now