I arranged my class to reverse URL notation (newb’s reaction to a finicky package). I have the sudoku directory in my home. It hold the binary packages for ‘Drools Planner’ in binaries and my sources. The directory is arranged like
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ ls src/main/java/in/co/technovia/sudoku/
App.class App.java~ helloworld.class helloworld.java~
App.java domain helloworld.java solution
My classpath points to . and the above-mentioned binaries of ‘Drools Planner’.
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ export | grep CLASSPATH
declare -x CLASSPATH=".:/home/jesvin/dev/drools/sudoku/binaries/*"
The App.java has this in first line: package in.co.technovia.sudoku;
I tried to run the App class in the root of my source using the fully qualified package name:
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java in.co.technovia.sudoku.helloworld
Exception in thread "main" java.lang.NoClassDefFoundError: in/co/technovia/sudoku/helloworld
Caused by: java.lang.ClassNotFoundException: in.co.technovia.sudoku.helloworld
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: in.co.technovia.sudoku.helloworld. Program will exit.
My question is kinda elementary to Java: how do I run the java command or set the CLASS_PATH so that the package runs fine?
The class file resides in the same folder as your java file (in your case), so you need to use
Then, to execute the class, use the command you posted in the question, it should work.
When your code is correctly compiled to the
binariesdirectory, you could add this directory to the classpath (not use ‘*’ in the end, because this adds all sub directories instead!). Then, check that there is a directory namedininside, as the directory structure must reflect the package structure.Further, I want to kindly ask you to follow the Java Naming Conventions and always start class names with a capital letter! Java Naming Conventions