2014-09-22 55 views
2

我今天開始學習java,使用當前的JDK編譯/運行和記事本++作爲編輯器。我不想使用IDE,除非我已經通過自己做這些事理解事情的工作方式,而不是點擊某個按鈕,所以我使用shell命令來編譯和運行我的第一個簡單程序。用於編譯和運行java代碼的不可缺少的標誌

不幸的是,我發現的大多數教程都覆蓋了使用NetBeans或Eclipse的示例,所以最後按下了一些按鈕並開始了魔法。

我明白當我用javac編譯代碼並在JVM中運行代碼時會發生什麼情況,但我需要認真的線索來了解它是否以正確的方式發生。

我知道,標誌非常適合這個目的,並且允許我控制由javac完成的編譯過程的幾乎所有步驟,並且在運行時由JVM控制,但oracle提供的正式標誌列表絕對是壓倒性的。

因此,正如標題所示,我正在尋找一些參考文獻提及並解釋編譯和運行Java代碼所需的最重要的標記,這些標記是安全和穩定的。我到目前爲止發現的任何東西都不是關心這個,使用IDE的默認配置或者是在遠遠高於我的水平上處理標誌的東西,所以我決定在這裏要求進一步提升。

+1

如果您只需鍵入'javac'或'java'並按回車鍵,您將獲得他們使用的所有選項。這是你在找什麼? – 2014-09-22 18:03:52

+1

NetBeans和Eclipse支持許多不同類型的項目,但其中大多數使用構建工具,如「ant」和「maven」。這些工具使用文本配置和編譯腳本,因此IDE只需維護它們(在項目目錄中查找'* .xml'文件),然後在單擊按鈕時要求'ant'或'maven'完成這項工作。 – mariusm 2014-09-22 22:11:36

+0

@mariusm:這是否意味着,XML文件中包含(完全)與編譯過程應如何完成相同的信息,我通常會在shell中輸入?我不知道IDE是這樣做的,所以也許他們對我當前的目的可能比我想象的更有趣。謝謝! – Wanderer 2014-09-23 07:18:45

回答

1

您只需輸入javacjava,然後按回車鍵,您將獲得他們使用的所有選項。你的輸出將是這樣的:

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 

C:\Users\StackOverflow>java 
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 
    -client  to select the "client" VM 
    -server  to select the "server" VM 
    -hotspot  is a synonym for the "client" VM [deprecated] 
        The default VM is client. 

    -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> 
        require the specified version to run 
    -showversion print product version and continue 
    -jre-restrict-search | -no-jre-restrict-search 
        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 m 
ore details. 

同樣,你會得到javac的輸出。

相關問題