Mac java.lang.ClassNotFoundException

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Mac java.lang.ClassNotFoundException

mike4850
Hi,

I was hoping someone might have some tips for how to troubleshoot running the supplied compiler on a Mac. I figure I'm doing something silly, but I haven't been able to figure it out.

When I try to run:
JackCompiler.sh ~/Desktop/nand2tetris/projects/09/HelloWorld

I get the error:
Compiling /Users/mynamehere/Desktop/nand2tetris/projects/09/HelloWorld
Error: Could not find or load main class Hack.Compiler.JackCompiler
Caused by: java.lang.ClassNotFoundException: Hack.Compiler.JackCompiler

I tried to add the various project tools to my PATH variable using the advice here https://www.nand2tetris.org/copy-of-nestedcall-1. I've also tried the full path for JackCompiler.sh just in case my path variable doesn't work, but I get the same error. I have confirmed the supplied compiler is in that location. I do have java 11.0.2 on my machine. I'm using the provided HelloWorld program, to eliminate any potential errors within the jack code.

I saw on another forum that the error might be an issue with the .jar file not being added to the classpath, but I think that should be taken care of in the .sh file right?

Anyway, if you have any thoughts on what to try please let me know. Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
Following, I'm having the same problem too on mac. All the other .sh programs run fine except for the compiler.
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

ivant
Please run the JackCompiler.sh with this command:

sh -x JackCompiler.sh path-to-jack-files

and copy and paste the debug info so we can troubleshoot.

The -x option will make shell to also print the commands that is executing.
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
This is the info from the terminal

+ unset CDPATH
++ test -L JackCompiler.sh
++ echo JackCompiler.sh
+ script=JackCompiler.sh
+ dir=/Users/hlaw/Desktop/Computer_System/nand2tetris/tools
++ dirname JackCompiler.sh
+ cd .
+ '[' '(' 1 -gt 1 ')' -o '(' path-to-jack-files = -h ')' -o '(' path-to-jack-files = --help ')' ']'
+ '[' 1 -eq 0 ']'
++ echo path-to-jack-files
++ sed -e 's/\(.\).*/\1/'
+ '[' p = / ']'
+ arg1=/Users/hlaw/Desktop/Computer_System/nand2tetris/tools/path-to-jack-files
+ echo Compiling /Users/hlaw/Desktop/Computer_System/nand2tetris/tools/path-to-jack-files
Compiling /Users/hlaw/Desktop/Computer_System/nand2tetris/tools/path-to-jack-files
+ java -classpath :bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar Hack.Compiler.JackCompiler /Users/hlaw/Desktop/Computer_System/nand2tetris/tools/path-to-jack-files
Error: Could not find or load main class Hack.Compiler.JackCompiler
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

ivant
Looks OK (although I was expecting that you'd replace path-to-jack-files with the actual path of the things you're trying to compile).

Probably something is missing in the tools directory. I suggest you download the software again https://www.nand2tetris.org/software and unpack it in a clean folder and try from there.
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
I downloaded the software again and upacked it in its own folder. It still doesn't want to compile:

Hazels-MacBook-Pro:tools hlaw$ sh -x JackCompiler.sh /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
+ unset CDPATH
++ test -L JackCompiler.sh
++ echo JackCompiler.sh
+ script=JackCompiler.sh
+ dir=/Users/hlaw/Desktop/nand2tetris/tools
++ dirname JackCompiler.sh
+ cd .
+ '[' '(' 1 -gt 1 ')' -o '(' /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack = -h ')' -o '(' /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack = --help ')' ']'
+ '[' 1 -eq 0 ']'
++ echo /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
++ sed -e 's/\(.\).*/\1/'
+ '[' / = / ']'
+ arg1=/Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
+ echo Compiling /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
Compiling /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
+ java -classpath :bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar Hack.Compiler.JackCompiler /Users/hlaw/Desktop/nand2tetris/projects/09/HelloWorld/Main.jack
Error: Could not find or load main class Hack.Compiler.JackCompiler

Is there something else I am missing?
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

ivant
Can you please open a terminal, go to the folder containing JackCompiler.sh and type the following command (best copy and paste it):

ls -l bin bin/lib

and then paste the response here?
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
Hazels-MacBook-Pro:tools hlaw$ ls -l bin bin/lib
bin:
total 8
-rw-rw-r--@  1 hlaw  staff   84 Aug 28  2016 Virtual Machine Emulator.dat
drwxrwxr-x@  7 hlaw  staff  224 Jan 27  2017 classes
drwxrwxr-x@ 11 hlaw  staff  352 Jan 27  2017 help
drwxrwxr-x@ 29 hlaw  staff  928 Jan 27  2017 images
drwxrwxr-x@  9 hlaw  staff  288 Jan 27  2017 lib
drwxrwxr-x@  5 hlaw  staff  160 Jan 27  2017 scripts

bin/lib:
total 712
-rw-rw-r--@ 1 hlaw  staff   4470 Mar 11  2016 AssemblerGUI.jar
-rw-rw-r--@ 1 hlaw  staff  27094 Mar 11  2016 Compilers.jar
-rw-rw-r--@ 1 hlaw  staff  59364 Mar 11  2016 Hack.jar
-rw-rw-r--@ 1 hlaw  staff  96666 Mar 11  2016 HackGUI.jar
-rw-rw-r--@ 1 hlaw  staff  81810 Mar 11  2016 Simulators.jar
-rw-rw-r--@ 1 hlaw  staff  68492 Mar 11  2016 SimulatorsGUI.jar
-rw-rw-r--@ 1 hlaw  staff  13643 Mar 11  2016 TranslatorsGUI.jar
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

ivant
All looks as it should and I'm really out of ideas what the problem might be. And I don't have a Mac so I can't test for problems.

There are a few threads here, discussing problems with MacOS Catalina. Here is one such thread: http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/macOS-Catalina-10-15-4-problem-td4034489.html

You might find some help there. Or, you'll have to wait for somebody with a Mac to respond and to try to help you. Sorry that I couldn't do more.
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
Thanks I appreciate your help.
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

wallezah
FYI - I found the problem it's the security feature of Catalina as stated in the thread you provided. Thanks for your time!!
Reply | Threaded
Open this post in threaded view
|

Re: Mac java.lang.ClassNotFoundException

mike4850
In reply to this post by ivant
Wow! It worked for me too, that's great. Thanks to you both!

I just continued on building my own compiler and it seemed to work fine, just a little more frustrating. Oh well.

Again, for other folks. I went to the linked linked article:
https://www.howtogeek.com/443611/how-macos-catalinas-new-security-features-work/
Went to Settings > Security & Privacy > Privacy (tab) > Files and Folders > then allowed Java to access Desktop Folder.