执行java程序_执行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

-classpath

A : separated list of directories, JAR archives,

and ZIP archives to search for class files.

-D=

set a system property

-verbose:[class|gc|jni]

enable verbose output

-version      print product version and exit

-version:

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[:...|:]

-enableassertions[:...|:]

enable assertions with specified granularity

-da[:...|:]

-disableassertions[:...|:]

disable assertions with specified granularity

-esa | -enablesystemassertions

enable system assertions

-dsa | -disablesystemassertions

disable system assertions

-agentlib:[=]

load native agent library , e.g. -agentlib:hprof

see also, -agentlib:jdwp=help and -agentlib:hprof=help

-agentpath:[=]

load native agent library by full pathname

-javaagent:[=]

load Java programming language agent, see java.lang.instrument

-splash:

show splash screen with specified p_w_picpath

See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值