I compiled a java project and generated .class files. If I try to run my code like below (refer https://stackoverflow.com/a/12044735/147530):
java com.mycompany.mysubdomain.App
I get this error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
understandable as I haven't specified the classpath where com.mysql.jdbc.Driver can be found. So I ran:
mvn dependency:build-classpath
to get classpaths of my dependencies. Then I have tried running like so:
java -classpath /Users/me/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar:/Users/me/.m2/repository/com/vividsolutions/jts/1.13/jts-1.13.jar:/Users/me/.m2/repository/junit/junit/4.11/junit-4.11.jar:/Users/me/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar com.mycompany.mysubdomain.App
but now I get this:
Error: Could not find or load main class com.mycompany.mysubdomain.App
I don't understand why its complaining now. Note the crucial thing - when I omitted the classpath it was able to find App. The ClassNotFoundException happened because it couldn't find a dependency. But now why is it complaining that it can't find the App to begin with? How can I fix this?