導航:首頁 > 源碼編譯 > jvm參數不使用編譯器

jvm參數不使用編譯器

發布時間:2023-05-21 01:53:38

⑴ 我寫了一些java程序,但只能在編譯器上才能運行,怎樣把它做成不用編譯器的呢

java運行是在jvm(java虛擬機)上才能運行的,只要你電腦裝了jdk,那就可以運行。
問題二:脫離編譯器運行,也就是說你要給他打包,用myeclipse把他打包成jar文件就可以了,具體操作網路一下有詳細操作,需要注意的是,打包時你項目所用到的jar依賴包也需要一起打包,否則啟動報錯。打包成jar後只要放在電腦有jdk虛擬機的機器上都可以運行,如果你還要把它打包成安裝文件,就像QQ,需要安裝的。就得用另一個軟體再打包一下成exe了,我只給你提供這樣的思路,具體怎麼弄還得你學習,

⑵ 如何在maven環境中設置JVM參數

在maven環境中設置JVM參數的方法:

1.建立遠程調試,埠為4000的設定為:

set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000

注意:suspend最好設定為n.設定上述參數後,在eclipse中新建遠程調試,設置埠為4000,這樣通過jetty:run啟動系統時就可以進行遠程調試了。

2.解決自動熱部署時java.lang.OutOfMemoryError: PermGen space問題解決這一問題只需要增大PermGen區,默認為 64m,設置方法為:

set MAVEN_OPTS=-XX:MaxPermSize=128M

maven簡介:

Maven項目對象模型(POM),可以通過一小段描述信息來管理項目的構建,報告和文檔的軟體項目管理工具。

Maven 除了以程序構建能力為特色之外,還提供高級項目管理工具。由於 Maven 的預設構建規則有較高的可重用性,所以常常用兩三行 Maven 構建腳本就可以構建簡單的項目。由於 Maven 的面向項目的方法,許多 Apache Jakarta 項目發文時使用 Maven,而且公司項目採用 Maven 的比例在持續增長。

JVM簡介:

JVM是Java Virtual Machine(Java虛擬機)的縮寫,JVM是一種用於計算設備的規范,它是一個虛構出來的計算機,是通過在實際的計算機上模擬模擬各種計算機功能來實現的。

原理:JVM是java的核心和基礎,在java編譯器和os平台之間的虛擬處理器。它是一種基於下層的操作系統和硬體平台並利用軟體方法來實現的抽象的計算機,可以在上面執行java的位元組碼程序。

java編譯器只需面向JVM,生成JVM能理解的代碼或位元組碼文件。Java源文件經編譯器,編譯成位元組碼程序,通過JVM將每一條指令翻譯成不同平台機器碼,通過特定平台運行。

⑶ 如何設置JVM參數

設置eclipse jvm參數

打開Eclipse 或者 MyEclipse

打開 Windows -> Preferences -> Java -> Installed JREs

在 Default VM Arguments輸入框內輸入: -Xms512m -Xmx512m

解釋:

-Xms是設置java虛擬機的最小分配內存;-Xmx則是最大分配內存;512m為內存空間

一般-Xmx設置為你電腦物理內存的1/4,而把-Xms和 -Xmx設置為一樣,

其實你可以設置得更大一些,只要系統能分配足夠的內存就可以了,如果設置過大系統會提示你的。

⑷ java 編譯優化問題

java編譯的結果是位元組碼而不是二進制,所以在運行時vm的優化才是重要的,包括VM的回收策略、分配給VM內存的大小都能在一定程度上影響性能。Sun的VM支持熱點編譯,對高頻執行的代碼段翻譯的2進制會進行緩存,這也是VM的一種優化。

IBM JVM處理數學運算速度最快,BEA JVM處理大量線程和網路socket性能最好,而Sun JVM處理通常的商業邏輯性能最好。不過Hotspot的Server mode被報告有穩定性的問題。

Java 的最大優勢不是體現在執行速度上,所以對Compiler的要求並不如c++那樣高,代碼級的優化還需要程序員本身的功底。

貼個java的運行參數:

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-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 proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-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
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-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

-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see

documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.

Java虛擬機(JVM)參數配置說明

在Java、J2EE大型應用中,JVM非標准參數的配置直接關繫到整個系統的性能。
JVM非標准參數指的是JVM底層的一些配置參數,這些參數在一般開發中默認即可,不需

要任何配置。但是在生產環境中,為了提高性能,往往需要調整這些參數,以求系統達

到最佳新能。
另外這些參數的配置也是影響系統穩定性的一個重要因素,相信大多數Java開發人員都

見過「OutOfMemory」類型的錯誤。呵呵,這其中很可能就是JVM參數配置不當或者就沒

有配置沒意識到配置引起的。

為了說明這些參數,還需要說說JDK中的命令行工具一些知識做鋪墊。

首先看如何獲取這些命令配置信息說明:
假設你是windows平台,你安裝了J2SDK,那麼現在你從cmd控制台窗口進入J2SDK安裝目

錄下的bin目錄,然後運行java命令,出現如下結果,這些就是包括java.exe工具的和

JVM的所有命令都在裡面。

-----------------------------------------------------------------------
D:\j2sdk15\bin>java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-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 proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-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
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-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
-----------------------------------------------------------------------
在控制台輸出信息中,有個-X(注意是大寫)的命令,這個正是查看JVM配置參數的命

令。

其次,用java -X 命令查看JVM的配置說明:
運行後如下結果,這些就是配置JVM參數的秘密武器,這些信息都是英文的,為了方便

閱讀,我根據自己的理解翻譯成中文了(不準確的地方還請各位博友斧正)
-----------------------------------------------------------------------
D:\j2sdk15\bin>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see

documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.

The -X options are non-standard and subject to change without notice.
-----------------------------------------------------------------------

JVM配置參數中文說明:
-----------------------------------------------------------------------
1、-Xmixed mixed mode execution (default)
混合模式執行

2、-Xint interpreted mode execution only
解釋模式執行

3、-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
設置zip/jar資源或者類(.class文件)存放目錄路徑

3、-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
追加zip/jar資源或者類(.class文件)存放目錄路徑

4、-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
預先載入zip/jar資源或者類(.class文件)存放目錄路徑

5、-Xnoclassgc disable class garbage collection
關閉類垃圾回收功能

6、-Xincgc enable incremental garbage collection
開啟類的垃圾回收功能

7、-Xloggc:<file> log GC status to a file with time stamps
記錄垃圾回日誌到一個文件。

8、-Xbatch disable background compilation
關閉後台編譯

9、-Xms<size> set initial Java heap size
設置JVM初始化堆內存大小

10、-Xmx<size> set maximum Java heap size
設置JVM最大的堆內存大小

11、-Xss<size> set java thread stack size
設置JVM棧內存大小

12、-Xprof output cpu profiling data
輸入CPU概要表數據

13、-Xfuture enable strictest checks, anticipating future default
執行嚴格的代碼檢查,預測可能出現的情況

14、-Xrs rece use of OS signals by Java/VM (see

documentation)
通過JVM還原操作系統信號

15、-Xcheck:jni perform additional checks for JNI functions
對JNI函數執行檢查

16、-Xshare:off do not attempt to use shared class data
盡可能不去使用共享類的數據

17、-Xshare:auto use shared class data if possible (default)
盡可能的使用共享類的數據

18、-Xshare:on require using shared class data, otherwise fail.
盡可能的使用共享類的數據,否則運行失敗

The -X options are non-standard and subject to change without notice.

⑸ java文件不用javac編譯(專家級別問題)

javac只是一個java編譯拿源改器的命令行界面(shell)。java開源以後,編譯器也可消判以被編程操作
//獲得編譯器對象
JavaCompiler c=ToolProvider.getSystemJavaCompiler();
CompilationTask t=c.getTask(.... );//獲得編譯任務,參數可以是文件或源碼字元串的裂睜流
t.call();//開始編譯

閱讀全文

與jvm參數不使用編譯器相關的資料

熱點內容
網盤忘記解壓碼怎麼辦 瀏覽:852
文件加密看不到裡面的內容 瀏覽:651
程序員腦子里都想什麼 瀏覽:430
oppp手機信任app在哪裡設置 瀏覽:185
java地址重定向 瀏覽:268
一年級下冊摘蘋果的演算法是怎樣的 瀏覽:448
程序員出軌電視劇 瀏覽:88
伺服器系統地址怎麼查 瀏覽:54
解壓游戲發行官 瀏覽:601
國外小伙解壓實驗 瀏覽:336
頂級大學開設加密貨幣 瀏覽:437
java重載與多態 瀏覽:528
騰訊應屆程序員 瀏覽:942
一鍵編譯程序 瀏覽:129
語音加密包哪個好 瀏覽:340
有什麼學習高中語文的app 瀏覽:283
安卓手機的表格里怎麼打勾 瀏覽:411
阿里雲伺服器有網路安全服務嗎 瀏覽:970
超解壓兔子視頻 瀏覽:24
單片機怎麼測負脈沖 瀏覽:176