Run dagger example
To run simple example, first build the project by Maven
mvn compile
then try to run the example by
java -cp target/classes/ coffee.CoffeeApp
The errors are
Exception in thread "main" java.lang.NoClassDefFoundError: dagger/Factory
The NoClassDefFoundError
is a common error in Java. The main reason is the JVM class loader cannot find the correct class. See how to for this error.
dagger/Factory
seems a method/class in Dagger library. Let us first see where is the library. Actually the dagger library in the directory of Maven default directory for third-party package. But when running the application, the class path does not include the path.
There are two solutions. First, we can add the necessary path in the command line options. However there is another way if you use Maven. See run java main in Maven. Using this method, we can run the application like this:
mvn exec:java -Dexec.mainClass="coffee.CoffeeApp"
Now it works.
File->import->Maven->Existing Maven Project
If the java compiler used in Eclipse is 1.5 or lower, there should be annoying error which shows "must override the superclass". The solution is to update java compiler >= 1.6.
Project->Java Compiler
. Mark off Use compliance from execution environment 1.5...
and choose newer version.
Windows->Preference->Maven->Discovery
and then Open Catalog
to choose m2e-apt
.Project->Java Compiler->Annotation Processing
to enable project specific setting
Maven->Update project