My program compiled fine. But the problems start when I try to run it.
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java App
Exception in thread "main" java.lang.NoClassDefFoundError: org/drools/planner/core/solution/Solution
Caused by: java.lang.ClassNotFoundException: org.drools.planner.core.solution.Solution
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: App. Program will exit.
I know that the interface Solution was correctly resolved in compile time.
Here is the offending class Sudoku that implements Solution:
package domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.drools.planner.api.domain.solution.PlanningEntityCollectionProperty;
import org.drools.planner.core.solution.Solution;
import org.drools.planner.core.score.SimpleScore;
public class Sudoku implements Solution<SimpleScore>{
...
And here is the App class that is supposed to use an instance of the Sudoku class
import java.util.ArrayList;
...
import org.drools.planner.config.XmlSolverConfigurer;
...
//solution too
import org.drools.planner.core.solution.Solution;
import solution.SudokuGenerator;
import domain.Sudoku;
public class App{
public static void main(String[] args){
SudokuGenerator sg = new SudokuGenerator();
Solution sudoku = sg.createSudoku();
Solver solver = createSolver();
solver.setPlanningProblem(sudoku);
solver.solve();
Sudoku result = (Sudoku) solver.getBestSolution();
result.displaySolution();
}
private static Solver createSolver(){
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure("solver.xml");
return configurer.buildSolver();
}
}
Is it the result of me wrongly casting between Sudoku and Solution?
My classpath is set as:
declare -x CLASSPATH=".:/home/jesvin/dev/drools/sudoku/binaries"
As @GPRathour wrote above, you need to add the jars from drools planner to the classpath.
I guess
/home/jesvin/dev/drools/sudoku/binariesis a directory. You need put jars there.Some thing like…
declare -x CLASSPATH=".:/home/jesvin/dev/drools/sudoku/binaries/drools-planner-core.jarA better approach will be to add jars in the command line via -classpath
java -classpath path/jar1;path/jar AppIn a exception stack you should always check the ’caused by ‘ messages. In this your real exception was
Caused by: java.lang.ClassNotFoundException: org.drools.planner.core.solution.Solution.( Other thing to note– Use packages. Having classes in appropriate packages helps lot in reading code later.)