• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoClassDefFoundError only in terminal

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I haven't done any programming in about 7 years (I basically forgot everything about programming), and the last I did was an intro to C++ class. I'm now taking an Intro to Java class, but I'm having some trouble with MacOS, NetBeans, and the terminal. I'm using Netbeams with Maven to run my first program (HelloWorld) on MacOS Ventura. It runs fine in Netbeans, but in terminal I get a NoClassDefFoundError. It compiles fine using the javac command, but when I try to run the program using the java command I get the aforementioned error. I haven't changed anything from the provided code. I also made sure the name of my project and is capitalized correctly and used the exact name when trying to run it in the terminal. I've been looking online for a few days now and nothing has worked (my professor couldn't help me either). I've attached some pictures of the IDE and well as terminal with the commands I used leading up to the error. Any help would be appreciated!
ideEDIT.jpg
[Thumbnail for ideEDIT.jpg]
terminalEDIT.jpg
[Thumbnail for terminalEDIT.jpg]
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not a Mac or Netbeans person but I'll give it a shot.

You cd'd to the wrong directory, you went too far down the chain. You need:
Now try
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carey Brown,

Thank you for your reply! I'll try your suggestion. for the part would I do it just like that without the quotation marks?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure about a Mac. Seeing as how what's between the quotes has no  spaces or special characters you should be able to omit the quotes but I don't think it does any harm if they are there.
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again Carey Brown,

Unfortunately neither option (with or without the quotation marks) worked for me, I get the same error as before.
ty4help.jpg
[Thumbnail for ty4help.jpg]
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you see that your 'cd' commands are generating error messages?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does Mac have a 'pwd' command (print working directory)?

or
echo $cwd

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could close the terminal and open a new one and that should reset your path (although that's an ugly way to do it).
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Carey,

Hmm, I didn't notice that. It definitely didn't do that before... I'll try your suggestion about the pwd and eco $cwd commands. But first I'll start with closing then reopening the terminal.
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Carey,

I've reattempted changing to the direct path with the cd command and also tried the pwd command, I've attached a picture of my result.
afterpwd.jpg
[Thumbnail for afterpwd.jpg]
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Type
Cut and paste output into a post here.
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again Carey,

I typed in the most recent command you suggested and here is the output

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try
You should see "HelloWorld.class"
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see the following when trying that command
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

-or-
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both commands resulted in the following

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm stumped. Your .java file should not have ended up in the target directory but that shouldn't be causing you a problem. Seeing as you seem to just be trying to get SOMETHING to work, I  would try removing anything package related temporarily. That would include the 'package' statement in the .java file, and the location of the .java file and tweaking the Maven file to not use any packages. Then compile and run without the -cp stuff or the path names.

I hesitate to suggest this because it could leave you with a big mess and I would normally be around to help you but it's almost midnight here and I'm turning in.
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll try that, thank you for your time and help!
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RH: welcome to the anch

Ronald Heron wrote:. . . thank you . . .

Well one, Carey
 
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the -cp option was having java look in the wrong place.  
Change to the classes folder and enter this command:

The package name gives the java command the path to where the class file is.
Using -cp "com/mycompany/helloworld" com/mycompany/helloworld/HelloWorld
has java looking in the helloworld folder for the package/path ie  com/mycompany/helloworld/HelloWorld

 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
General observations.

MacOS is a BSD-descended Unix OS. As such, if you know Linux, you're mostly fine using that knowledge on MacOS. Especially since after Linux stole so much from Unix, latterly Unix has been stealing from Linux!

No, you don't need quoted filenames on the command line unless they have characters that have special meaning to the shell such as blank spaces. Quotes om the shell are double-quotes (shell environment variables are expanded), single quotes (shell environment variables are NOT expanded) and back-tick quotes, which cause the quoted string to be executed as a shell command and piped to the current shell.

It's hard to read the screenshots and it's perilous to deduce filesystem paths from the GUI display, since an IDE will often arrange "file listings" by logical function and not actual filesystem path. But it looks like the proper sequence should be something like this:

Note that for safety's sake I used an absolute path for the "cd" command and it may need to be tweaked if [censored]-MacBook-Air isn't at the root of the filesystem.

And definitely don't forget (just in case) that all filenames and paths in Java are case-sensitive and doubly-so in Unix-like OS's where the filesystems are case-sensitive also. I periodically burn myself by not hitting the SHIFT key in the right places. Or vice versa.
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:I think the -cp option was having java look in the wrong place.  
Change to the classes folder and enter this command:

The package name gives the java command the path to where the class file is.
Using -cp "com/mycompany/helloworld" com/mycompany/helloworld/HelloWorld
has java looking in the helloworld folder for the package/path ie  com/mycompany/helloworld/HelloWorld



Hi Norm,

Thank you for your reply! I'll give this a try right now
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Welcome to the thread and thank you for taking the time to reply

I'm not familiar with Linux unfortunately, but I'll take some time to make sure I learn all of the proper terminal commands if that helps at all
 
Ronald Heron
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Norm,

I bear good news... your suggestion worked! So recap. In the future with any program I create using Netbeans on this system, if I want to run it via terminal, I should nagivate to the classes folder and enter a command similar to the one you suggested?



Assuming I don't change where I saved my project of course.
 
I don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic