#Could not find or load main class caused by ClassNotFoundException
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
correct main class in my JAR file?
The "Could not find or load main class" error is typically caused by the JVM not being able to locate your main class during runtime. This error is usually due to one of the following reasons:
-
Incorrect package structure: Make sure that your main class is in the correct package structure defined in the manifest file.
-
Incorrect classpath: Ensure that the classpath is correctly set in your manifest file or command line arguments.
-
Missing or incorrect manifest file: Double-check your manifest file to ensure that it correctly specifies the main class and that it is located in the correct directory within your JAR file.
-
Incorrect main class name: Verify that the fully qualified name of your main class matches exactly what is specified in the manifest file.
-
JAR file corruption: If none of the above solutions work, try rebuilding your JAR file as it may be corrupted.
To troubleshoot this issue, you can try running your JAR file with a verbose output option (-verbose:class) to see if it provides more information about where the JVM is trying to look for your main class. Additionally, check for any typos or syntax errors in your manifest file and ensure that all necessary dependencies are included in your JAR file.
I have the module path also @untold ingot
can you give more info?
enough to run this situation locally / recreate it?
the command you are using to launch your code
etc
so java -jar file.jar works
but im trying to run it without java- jar
file.jar in terminal
then i get class not found exception
what are the exact commands you mean?
just cd into the path where the jar lives
then file.jar in terminal
I dont want to do the extra java options @untold ingot
if its a jar it has to be with java -jar
can you please just write out the command that works and the one that does not
You could use a batch script for windows that does that for you
for what I understand is that java -jar x command is too long to write and "x" command didn't work
is that or I'm wrong @sharp osprey
if that is the case there is a way to make it work
but @hollow dew don't call people "too lazy to __"
it doesn't really foster a good environment
ok
Yes but it didn’t work doing x
But it worked for others on my team but they don’t know why and couldn’t show me
@hollow dew @untold ingot
So the way to make thing.jar work as a command is to prepend a "shebang" line to it
only works on mac/linux
but basically if the first bytes of a file are #!java -jar
it will launch the file with java -jar
now that makes it unusable with java -jar
and Nemux is right, it is silly to go this far to avoid writing java -jar
one way to save run configuration stuff is to put it into a text file
if you make a file like run.txt
and put in it
-jar yourthing.jar
you can say
On Windows its with a batch file
java @run.txt
and that works
which is more amicable to that command growing in whatever way
Or
Basically my lead developer has made it incumbent that he just runs c:/file/to/jar/thing.jar and run it as a script without making adjustments
better you set a program in your path that runs java -jar
Nope company work @hollow dew @untold ingot
File association I think
how are you building your code
IntelliJ artifacts build with module and dependency look for main class then build the jar
I urge him just add Java -jar but he doesn’t think it’s a good idea
no offense, but that sounds very amateur. Is your lead dev participating at all?
He’s not keen on change or growth
what is the thing you are making?
It’s just a etl desktop app
what are your dependencies
and how do you get your app to clients or are you running it on your end
The app renders data
And that data goes to file system and is mapped to FileZilla to then ftp data
so its basically a script for you guys
Yup
Yeah
and your lead is the one running it?
Yeah
He’s not a lead per say he’s like a sys / db admin
22
The thing is this app is not client facing
are you aware that you do not need to compile your code in 22
Oh how so
We have code that’s like 8 and below
like a python script
So we were migrating to Java 22
But in the process it has all these classpath errors can’t find manifest or main class blah blah
Well it’s getting my lead to understand that he’s not a programmer and how he’s been doing it for years is how it’ll be
I still don't understand why to go this far just to not write java -jar
well lets say for a moment that maybe the "run a jar directly" thing should work out
like you run the program very often
and there is no way to change this guy's opinion
we have to assume that you are building your jar wrong
so can you maybe screenshot your folder structure?
Okay
also which class wasnt found when you ran this stuff before
how so? I think it would say main class is not in manifest rather that class not found
well he must want to have an uberjar. that would be going wrong
or rather he needs an uberjar to make his boss's command work
oh
nononono
"here" meaning the IDE is meaningless
tell us the exact error you get
when it doesn't work
not part of it
exactly what it says
I think when he runs thing.jar in cmd windows try to open it like java thing.jar.class
and that file doesnt exist
that doesnt show the error
tell what error gives running your app in cmd without java -jar
@sharp osprey
I know you said class not found but send full error
show full error log
yes
also r/screenshotsarehard
full error log`
caused by java.lang.ClassnotFoundException
that's it?
yup
basically windows tries to run it as java yourapp.jar
trying to find yourapp.jar.class
I will try if that happens on my windows
send the right part
the right as as in opposite of left? lol
youre not showing full error
its just fle directories
r/screenshotsarehard 😞
where my out folder is for the artifacts
well I will try on my pc if its just bad file associatipn by windows
@sharp osprey yes it is
does double clicking the jar makes it open with java?
that is to set file association
your app?
that shouldnt happen
@sharp osprey Use the snipping tool
to take screenshots
rather than your phone
and okay check to see if you have an extra version of java installed
if its opening with an old java it might crash instantly
ut also
WHAT FUCKING CLASS CANT IT FIND
haha
literally thats it
the part we need to see is what is to the right of ClassNotFoundException
Learn how to use Snipping Tool to capture a screenshot, or snip, of any object on your screen, and then annotate, save, or share the image.
how do you know what part of the picture says this
okay now we are getting somewhere
hmm
so for some reason your jar is trying to load a file path as its main class
do you have winrar or 7zip?
7zip
can you open the jar file in 7zip
and look at what is in the Manifest.MF
if you need to, rename the file to .zip
...though it should work without that
its already working with java -jar so this shouldn't be a problem
ive got a manifest file
oh exactly that?
the manifest you find inside the jar
yeah
when you look at it in 7zip
i'm trying to get a handle on what happens when you are running the jar directly
for some reason i have meta-inf outside of src and one in src
can you try the same thing in PowerShell?
oh, thats interesting
screenshots
those files have different sizes
what is in the one on the left (the one not in src)
maybe
okay so if thats not the issue i'm back to being suspicious of your java setup
should i delete one of them ?
nah its fine
because being able to run a jar directly without java -jar isn't a normal state of affairs
its pretty normal for someone to be able to double click a jar
but running the jar as a file directly...first i've seen it
is your lead aware that he needs to / would need to be on java 22?
yeah he has 22 on his machine
does he have a similar issue when running it?
have him test it then
then yeah can you go to Add/Remove programs?
and search for java
oh what
no you don't want java se?
sorry jdk 22
okay well still go to the add/remove programs
we are gonna see if you have 2 versions of java
uninstall the older version if you have one, and use jarfix tool
isnt java se developmentt kit just jdk 22
to fix the file association
yeah
but java has gotten a lot of wierd names
what about jres do i need to change that?
and what happens sometimes is people install a JRE
or is it embedded
yeah you shouldn't have any
the "JDK" is just "Java + the compiler and stuff"
i don't know what jarfix is so i'll leave it to nemux
also i need to get some sleep
but we've narrowed down what the issue might be
thats progress
Also check all checkboxes in installer
yeah
solved man
thanks a ton
okay so we now know
fileassociations been hijacked
what is the alternative to jarfix
would we have to go regedit?
or install a JDK that solves that issue
like Azul's one
