I'd like to know other than launching it from a program such as eclipse and other than from using the exec maven plugin, is there any other开发者_如何学编程 way to launch a java project?
Use the Java application launcher which comes packaged with the JDK. In its most basic form, the command line usage looks like this:
java MyMainClass
You may find it useful to use the -cp
flag to set the classpath, and the -jar
flag to launch the application from a jar file:
java -cp C:\java\MyClasses;C:\java\OtherClasses -jar myProgram.jar
See the documentation for other useful flags. For more information on the basic Java command line tools, see http://download.oracle.com/javase/7/docs/technotes/tools/#basic.
There is also the options of packaging up all of your classes and resources inside a jar and providing a manifest file.
http://download.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
That way when you double click the jar, if the file association is set up correctly, it will launch your application.
I always use the maven-assembly-plugin to build a jar-with-dependencies. Then you can typically execute with
java -jar my-app-jar-with-dependencies.jar
精彩评论