#Could not find or load main class caused by ClassNotFoundException

1 messages · Page 1 of 1 (latest)

sharp osprey
#

I always get Could not find or load main class caused by ClassNotFoundException why is this despite having a manifest pointing to the main class / entry point I also have jars I have imported in the modules what could be the issue it runs fine in intellij but not in terminal

jolly sorrelBOT
#

<@&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>.

#
TJ-Bot
I always get Could not find or load main class caused by ClassNotFoundException why is this despite having a manifest pointing to the main class / entry point I also have jars I have imported in the modules what could be the issue it runs fine in intellij

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:

  1. Incorrect package structure: Make sure that your main class is in the correct package structure defined in the manifest file.

  2. Incorrect classpath: Ensure that the classpath is correctly set in your manifest file or command line arguments.

  3. 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.

  4. Incorrect main class name: Verify that the fully qualified name of your main class matches exactly what is specified in the manifest file.

  5. 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.

untold ingot
#

how are you running the code?

#

it sounds likely you are missing a --module-path

sharp osprey
#

I have the module path also @untold ingot

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

sharp osprey
#

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

untold ingot
#

what are the exact commands you mean?

sharp osprey
#

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

hollow dew
untold ingot
#

can you please just write out the command that works and the one that does not

hollow dew
hollow dew
#

is that or I'm wrong @sharp osprey

untold ingot
#

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

hollow dew
#

ok

sharp osprey
#

But it worked for others on my team but they don’t know why and couldn’t show me

#

@hollow dew @untold ingot

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

hollow dew
untold ingot
#
java @run.txt
#

and that works

#

which is more amicable to that command growing in whatever way

hollow dew
#

Or

sharp osprey
#

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

hollow dew
#

better you set a program in your path that runs java -jar

untold ingot
#

is this a school project?

#

and okay if i'm guessing how that can even work

sharp osprey
#

Nope company work @hollow dew @untold ingot

untold ingot
#

maybe some old JRE for desktop crap?

#

would auto associate .jar with java?

hollow dew
#

File association I think

sharp osprey
#

The thing is we are on Java 22

#

The latest Java

untold ingot
#

how are you building your code

sharp osprey
#

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

untold ingot
#

no offense, but that sounds very amateur. Is your lead dev participating at all?

sharp osprey
#

He’s not keen on change or growth

untold ingot
#

what is the thing you are making?

sharp osprey
#

It’s just a etl desktop app

untold ingot
#

what are your dependencies

sharp osprey
#

Delivering data to clients

#

MSsql, some gui jars also

untold ingot
#

and how do you get your app to clients or are you running it on your end

sharp osprey
#

The app renders data

#

And that data goes to file system and is mapped to FileZilla to then ftp data

untold ingot
#

so its basically a script for you guys

sharp osprey
#

Yup

untold ingot
#

that ships stuff over ftp

#

(ultimately)

sharp osprey
#

Yeah

untold ingot
#

and your lead is the one running it?

sharp osprey
#

Yeah

untold ingot
#

Customer is always right on matters of taste, but

#

you are on 21 right?

#

or err 22

sharp osprey
#

He’s not a lead per say he’s like a sys / db admin

#

22

#

The thing is this app is not client facing

untold ingot
#

are you aware that you do not need to compile your code in 22

untold ingot
#
java src/Main.java
#

instead of a class name you can put a file

sharp osprey
#

We have code that’s like 8 and below

untold ingot
#

like a python script

sharp osprey
#

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

untold ingot
#

i mean

#

you are building it ad-hoc from intellij

#

I would expect shit to be broken

sharp osprey
#

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

hollow dew
untold ingot
#

well lets say for a moment that maybe the "run a jar directly" thing should work out

hollow dew
#

like you run the program very often

untold ingot
#

and there is no way to change this guy's opinion

sharp osprey
#

Nope

untold ingot
#

we have to assume that you are building your jar wrong

#

so can you maybe screenshot your folder structure?

sharp osprey
#

Okay

untold ingot
#

also which class wasnt found when you ran this stuff before

hollow dew
untold ingot
#

or rather he needs an uberjar to make his boss's command work

sharp osprey
#

It weren’t specific

#

Those jars I have to add to module libraries

untold ingot
#

I see an nbproject folder

#

maybe it will magically work if you open it in netbeans?

sharp osprey
#

It works here

#

Just not in terminal without Java -jar file.jar

untold ingot
#

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

sharp osprey
hollow dew
#

I think when he runs thing.jar in cmd windows try to open it like java thing.jar.class

#

and that file doesnt exist

hollow dew
#

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

sharp osprey
hollow dew
#

show the one that gives error

sharp osprey
#

Works like a charm

#

But without it

hollow dew
#

show full error log

hollow dew
hollow dew
sharp osprey
#

could not find or load main class

#

when i do prod_feed_v2.jar by itself

hollow dew
sharp osprey
#

caused by java.lang.ClassnotFoundException

hollow dew
#

that's it?

sharp osprey
#

yup

hollow dew
#

trying to find yourapp.jar.class

#

I will try if that happens on my windows

sharp osprey
hollow dew
sharp osprey
#

the right as as in opposite of left? lol

hollow dew
sharp osprey
#

its just fle directories

hollow dew
#

r/screenshotsarehard 😞

sharp osprey
#

where my out folder is for the artifacts

hollow dew
#

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

sharp osprey
#

it does a flash thing

#

then stops straight away

hollow dew
sharp osprey
#

yeah

#

something opens then closes straight away rather

hollow dew
#

that shouldnt happen

untold ingot
#

@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

sharp osprey
#

haha

untold ingot
#

thats all i want to know

#

is it from your stuff or your libraries

#

or the jdk

hollow dew
#

how I can't say the F word too

#

lol

#

@sharp osprey Send FULL error message

sharp osprey
#

literally thats it

hollow dew
#

some text isnt shown

untold ingot
#

the part we need to see is what is to the right of ClassNotFoundException

sharp osprey
hollow dew
#

it tries to open with java for some reason

sharp osprey
#

how do you know what part of the picture says this

untold ingot
#

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?

sharp osprey
#

7zip

untold ingot
#

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

hollow dew
sharp osprey
#

ive got a manifest file

untold ingot
#

the contents

sharp osprey
#

this

untold ingot
#

oh exactly that?

sharp osprey
#

the 7zip folders or the manifest

#

yeah

untold ingot
#

the manifest you find inside the jar

sharp osprey
#

yeah

untold ingot
#

when you look at it in 7zip

#

i'm trying to get a handle on what happens when you are running the jar directly

sharp osprey
#

for some reason i have meta-inf outside of src and one in src

untold ingot
#

can you try the same thing in PowerShell?

untold ingot
#

screenshots

sharp osprey
#

sure

untold ingot
#

those files have different sizes

#

what is in the one on the left (the one not in src)

sharp osprey
#

yeah

#

that might be because of whitespace

untold ingot
#

maybe

#

okay so if thats not the issue i'm back to being suspicious of your java setup

sharp osprey
#

should i delete one of them ?

untold ingot
#

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?

sharp osprey
#

yeah he has 22 on his machine

untold ingot
#

does he have a similar issue when running it?

sharp osprey
#

he hasn't tested it yet

#

but my co developer has and it works

untold ingot
#

have him test it then

sharp osprey
#

so i think its my set up

#

ive reinstalled javase though

untold ingot
#

then yeah can you go to Add/Remove programs?

#

and search for java

#

oh what

#

no you don't want java se?

sharp osprey
#

sorry jdk 22

untold ingot
#

okay well still go to the add/remove programs

#

we are gonna see if you have 2 versions of java

hollow dew
sharp osprey
#

isnt java se developmentt kit just jdk 22

hollow dew
#

to fix the file association

untold ingot
#

yeah

sharp osprey
#

or should i say jdk 22

#

okay

untold ingot
#

but java has gotten a lot of wierd names

sharp osprey
#

what about jres do i need to change that?

untold ingot
#

and what happens sometimes is people install a JRE

sharp osprey
#

or is it embedded

untold ingot
#

yeah you shouldn't have any

sharp osprey
#

cool

#

ill uninstall then install again

#

then also use jarfix?

untold ingot
#

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

sharp osprey
#

from which provider

#

thanks @untold ingot

untold ingot
hollow dew
#

Also check all checkboxes in installer

sharp osprey
#

oh it worked straight away

#

jarfix

hollow dew
#

so it is solved?

sharp osprey
#

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?

hollow dew
#

like Azul's one

sharp osprey
#

i saw an alternative

#

HKEY_ etc

#

regedit

#

Im guessing jarfix does this for you

#

but isually making changes on regedit requires you to restart your computer

#

but i never did so

#

so it may be doing something different

#

ah well its solved thanks again @hollow dew

sharp osprey
#

Thank you @hollow dew

#

Thank you @untold ingot