I have been at this problem for a few days now, don't know why it is still happening. I have tried other solutions that have been posted on stackoverflow but no luck.
Below the following code is from the book crafting interpreters in java.
In IntelliJ 2019.4
this error always pop up when I am trying to run the .jar
file.
Error: Could not find or load main class com.jam.Jam
Caused by: java.lang.ClassNotFoundException: com.jam.Jam
I have built the .jar
file and setting the main class as com.jam.Jam
and the class path for the .jar
file as /home/username/Jam-Programming_Language/src/com/jam/Scanner.Scanner
.
This is the layout of my project directory.
The following solutions I have tried:
- Open Project Structure
- Select Modules, then click on the module for which you want the dependency
- Choose the Dependencies tab
- Click the '+' at the bottom of the page and choose the appropriate way to connect to the library file. If the jar file is already listed in Libraries, then select 'Library'.
and
- Go to the Project Structure, click on Modules, and click on your Module
- Choose the "Dependencies" tab
- Click the "+" button on the right-hand side and select "Jars or directories..."
- Add the directory(ies) you want (note you can multi-select) and click OK In the dialog that comes up, select "classes" and NOT "jar directory" Make sure you're using that Module in your run target
It had no effect apparently. Any clue on what I should do?
Edit: Uploaded wrong screenshot, replaced screenshot.