首页 > 代码库 > 执行java程序是不是只能java -jar?
执行java程序是不是只能java -jar?
java -jar xxx.jar params 的形式用了这么多年,都没在意原来java的执行命令可以多元的。
这两天刚好在看rocketmq,顺便看了下它的shell脚本,然后才发现原来我这么多年的java -jar有多么的无知。
先来一段命令:
java -Djava.ext.dirs=$ROCKETMQ_HOME/lib -cp $ROCKETMQ_HOME/lib/rocketmq-example-3.5.8.jar com.alibaba.rocketmq.example.simple.Producer
这段命令是为了测试rocketmq的消息产生类产生消息。
于是回头再看一下java -help,瞬间知道了。那我们许多的工程写法,其实都不用纠结java打包的启动类是否在打包时候已经打入,也不用纠结一个jar包有N多个入口。
2012年时候我在某个项目做一个二级中心的时候,那时候为了一个工程中的三个入口都被调用到,同一套代码,配置了三个META-INF,里面配置了入口类,同时打了三个jar,如果改动代码再打包,费时费力。
现在回想,如果现在来做,就是打一个jar包,编三个shell脚本,瞬间解决一切。那些创造这些事务的人真是天才,使用的人可能就需要无尽的学习。
[rocketmq@cent65-1 ~]$ java -help
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
本文出自 “一枝花傲寒” 博客,请务必保留此出处http://feiweihy.blog.51cto.com/6389397/1868120
执行java程序是不是只能java -jar?