Reputation:
I have java class in folder D:\myProjects\new_example:
package new_example;
import com.google.gson.Gson;
class MyClass{
public static void main(String[] args) {
MyClass myClass = new MyClass();
Gson gson = new Gson();
System.out.println(gson.toJson(myClass.getMyDate()));
}
public String getMyDate(){
return "Hello";
}
}
How do to run this class in command Line (cmd) from disk D:? (If gson-2.2.4.jar is located: D:\library\gson-2.2.4.jar AND MyClass.java in D:\myProjects\new_example\MyClass.java), use classpath... How do to run it..?
Upvotes: 2
Views: 14249
Reputation: 713
I would suggest trying this:
java -cp "jar_name.jar;libs/*" com.test.App
jar_name.jar : your jar name with .jar extension
libs/* : relative path to your dependency jars
com.test.App : Class with main(String[]) method
Upvotes: 1
Reputation: 43087
Try this from the directory D:\myProjects:
java -cp D:\library\gson-2.2.4.jar new_example.MyClass
Upvotes: 0