I have the following directory structure:
folder1/
folder2/
compiler.java
For a school assignment, we have to be able to run the following commands from folder1:
javac folder2/compiler.java
java folder2/compiler
The compilation with javac works. When I try to run it with the above java command, I get a
Exception in thread "main" java.lang.NoClassDefFoundError: folder2/compiler (wrong name: compiler)
You have two options.
If your class
compileris in the default package do this. (No package declaration)Otherwise, if your class
compileris in the packagefolder2then do this.You can put
complierin thefolder2package by putting a package declaration at the top ofcompiler.java