執行java程式是不是只能java -jar?

來源:互聯網
上載者:User

標籤:java -jar -cp -d

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指令碼,瞬間解決一切。那些創造這些事務的人真是天才,使用的人可能就需要無盡的學習。


[[email protected] ~]$ 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?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.