天天看點

Java指令行工具總結

Java

指令行工具總結

1、指令

C/Documents and Settings/Zianed>ls ‘%JAVA_HOME%’/bin

HtmlConverter.exe  javap.exe       jstatd.exe        rmid.exe

appletviewer.exe   javaw.exe       jvisualvm.exe     rmiregistry.exe

apt.exe            javaws.exe      keytool.exe       schemagen.exe

beanreg.dll        jconsole.exe    kinit.exe         serialver.exe

extcheck.exe       jdb.exe         klist.exe         servertool.exe

idlj.exe           jhat.exe        ktab.exe          tnameserv.exe

jar.exe            jinfo.exe       msvcr71.dll       unpack200.exe

jarsigner.exe      jli.dll         native2ascii.exe  wsgen.exe

java-rmi.exe       jmap.exe        orbd.exe          wsimport.exe

java.exe           jps.exe         pack200.exe       xjc.exe

javac.exe          jrunscript.exe  packager.exe

javadoc.exe        jstack.exe      policytool.exe

javah.exe          jstat.exe       rmic.exe

需要獲得其中的幫助使用XX -help即可

Basic Tools

These tools are the foundation of the JDK. They are the tools you use to create and build applications.

Tool Name

Brief Description

Links to Reference Pages

javac

The compiler for the Java programming language.

[Solaris and Linux

] [Windows

]

java

The launcher for Java applications. In this release, a single launcher is used both for development and deployment.

The old deployment launcher, jre

, is no longer provided.

javadoc

API documentation generator.

See Javadoc Tool

page for doclet and taglet APIs.

apt

Annotation processing tool.

See Annotation Processing Tool

for program annotation processing.

[Solaris, Linux, and Windows

appletviewer

Run and debug applets without a web browser.

jar

Create and manage Java Archive (JAR) files.

See Java Archive Files

page for the JAR specification.

jdb

The Java Debugger.

See JPDA

for the debugger architecture specifications.

javah

C header and stub generator. Used to write native methods.

javap

Class file disassembler

extcheck

Utility to detect Jar conflicts.

Security Tools

These security tools help you set security policies on your system

and create apps that can work within the scope of security policies set

at remote sites.

keytool

Manage keystores and certificates.

jarsigner

Generate and verify JAR signatures.

policytool

GUI tool for managing policy files.

These security tools help you obtain, list, and manage Kerberos tickets.

kinit

Tool for obtaining Kerberos v5 tickets.

Equivalent functionality is available on the Solaris operating

environment via the kinit tool. For example, for Solaris 8, see the kinit reference page

.

[Linux

] [Windows

klist

Command-line tool to list entries in credential cache

and key tab. Equivalent functionality is available on the Solaris

operating environment via the klist tool. For example, for Solaris 8,

see the klist reference page

ktab

Command-line tool to help the user manage entires in

the key table. Equivalent functionality is available on the Solaris

operating environment via the kadmin tool. For example, for Solaris 8,

see the kadmin reference page

Internationalization Tools

This tool helps to create localizable apps.

native2ascii

Convert text to Unicode Latin-1.

Remote Method Invocation (RMI) Tools

These tools help to create apps that interact over the Web or other network.

rmic

Generate stubs and skeletons for remote objects.

rmiregistry

Remote object registry service.

rmid

RMI activation system daemon.

serialver

Return class serialVersionUID.

Java IDL and RMI-IIOP Tools

These tools are used when creating applications that use OMG-standard IDL and CORBA/IIOP.

tnameserv

Provides access to the naming service.

idlj

Generates .java files that map an OMG IDL interface

and enable an application written in the Java programming language to

use CORBA functionality.

orbd

Provides support for clients to transparently locate

and invoke persistent objects on servers in the CORBA environment. ORBD

is used instead of the Transient Naming Service, tnameserv. ORBD

includes both a Transient Naming Service and a Persistent Naming

Service. The orbd

tool incorporates the functionality

of a Server Manager, an Interoperable Naming Service, and a Bootstrap

Name Server. When used in conjunction with the servertool, the Server

Manager locates, registers, and activates a server when a client wants

to access the server.

servertool

Provides ease-of-use interface for the application programmers to register, unregister, startup, and shutdown a server.

Java Deployment Tools

Utilities for use in conjunction with deployment of java applications and applets on the web.

pack200

Transforms a JAR file into a compressed pack200 file

using the Java gzip compressor. The compressed packed files are highly

compressed JARs, which can be directly deployed, saving bandwidth and

reducing download time.

unpack200

Transforms a packed file produced by pack200 into a JAR file.

Java Plug-in Tools

Utilities for use in conjunction with the Java Plug-in.

Brief Description with Links to Reference Pages

htmlconverter

Converts an HTML page (file) containing applets to the OBJECT / EMBED tag format for Java Plug-in.

Java Web Start Tools

Utilities for use in conjunction with the Java Web Start.

javaws

Command line tool for launching Java Web Start and setting various options.

See Java Web Start Guide

for more information.

Monitoring and Management Tools

You can use the following tools to monitor JVM performance and

resource consumption. The tools described in this section are

unsupported and experimental

, and should be used with that in mind. They may not be available in future JDK versions.

Platform support:

jconsole: all platforms.

jps, jstat, and jstatd: all platforms except Windows 98 and Windows ME.

For more information, see Monitoring and Management for the Java Platform

jconsole

Experimental

: Java

Monitoring and Management Console – JMX-compliant graphical tool for

monitoring a Java virtual machine. It can monitor both local and remote

JVMs.

jps

: JVM Process Status Tool – Lists instrumented HotSpot Java virtual machines on a target system.

jstat

: JVM

Statistics Monitoring Tool – Attaches to an instrumented HotSpot Java

virtual machine and collects and logs performance statistics as

specified by the command line options.

jstatd

: JVM jstat

Daemon – Launches an RMI server application that monitors for the

creation and termination of instrumented HotSpot Java virtual machines

and provides a interface to allow remote monitoring tools to attach to

Java virtual machines running on the local system.

Troubleshooting Tools

The following tools can be used for specific troubleshooting tasks. The tools described in this section are unsupported and experimental

in nature and should be used with that in mind. They may not be available in future JDK versions.

These tools are not currently available on Windows platforms

jinfo

Configuration Info for Java – Prints configuration information for for

a given process or core file or a remote debug server.

jmap

– Memory Map

for Java – Prints shared object memory maps or heap memory details of a

given process or core file or a remote debug server.

jsadebugd

– Serviceability Agent Debug Daemon for Java – Attaches to a process or core file and acts as a debug server.

jstack

– Stack Trace for Java – Prints a stack trace of threads for a given process or core file or remote debug server.

2

、指令簡單介紹

2.1 HtmlConverter

2.2 appletviewer

檢視Applet程式的運作結果。

2.3 apt

2.4 extcheck

2.5 idlj

2.6 jar

将一個檔案打成jar包,以提供給給程式,友善使用。

bash-3.2$ jar -help

非法選項:h

用法: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files …

選項包括:

-c  建立新的歸檔檔案

-t  列出歸檔目錄

-x  解壓縮已歸檔的指定(或所有)檔案

-u  更新現有的歸檔檔案

-v  在标準輸出中生成詳細輸出

-f  指定歸檔檔案名

-m  包含指定清單檔案中的清單資訊

-e  為捆綁到可執行 jar 檔案的獨立應用程式

指定應用程式入口點

-0  僅存儲;不使用任何 ZIP 壓縮

-M  不建立條目的清單檔案

-i  為指定的 jar 檔案生成索引資訊

-C  更改為指定的目錄并包含其中的檔案

如果有任何目錄檔案,則對其進行遞歸處理。

清單檔案名、歸檔檔案名和入口點名的指定順序

與 “m”、”f” 和 “e” 标志的指定順序相同。

示例 1:将兩個類檔案歸檔到一個名為 classes.jar 的歸檔檔案中:

jar cvf classes.jar Foo.class Bar.class

示例 2:使用現有的清單檔案 “mymanifest” 并

将 foo/ 目錄中的所有檔案歸檔到 “classes.jar” 中:

jar cvfm classes.jar mymanifest -C foo/ .

bash-3.2$ jar -cvf zianed.jar *.class

标明清單(manifest)

增加:A.class(讀入= 112) (寫出= 105)(壓縮了 6%)

增加:B.class(讀入= 246) (寫出= 184)(壓縮了 25%)

bash-3.2$

2.7 jarsigner

2.8 java-rmi

2.9 java

執行java語言,期中包括了一部分的java執行可以使用和引入的參數;也包括了部分執行時的資訊收集資訊。

bash-3.2$ java -version

java version “1.6.0_10″

Java(TM) SE Runtime Environment (build 1.6.0_10-b33)

Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode)

2.10 javac

java編譯器,将java源檔案編譯成可以供jvm執行的二進制class檔案。

bash-3.2$ javac -version

javac 1.6.0_10

2.11 javadoc

根據源檔案生成java的doc文檔API。

2.12 javah

bash-3.2$ cd zianed

bash-3.2$ ls B.*

B.class  B.java

bash-3.2$ cd ..

bash-3.2$ javah zianed.B

bash-3.2$ ls

zianed  zianed_B.h

2.13 javap

将java位元組碼檔案進行反編譯的工具。

bash-3.2$ javap zianed.B

Compiled from “B.java”

public class zianed.B extends java.lang.Object implements zianed.A{

public zianed.B();

public void print();

public native java.lang.String getInfo();

}

2.14 javaw

The javaw

command is identical to java

, except that with javaw

there is no associated console window. Use javaw

when you don’t want a command prompt window to appear. The javaw

launcher will, however, display a dialog box with error information if a launch fails for some reason.

2.15 javaws:

2.16 jconsole

Java Monitoring and Management Console

啟動java程序監控和管理控制台。監控和分析jvm的運作情況。

用法: jconsole [ -interval=n ] [ -notile ] [ -pluginpath <path> ] [ -version ] [ connection ...]

-interval   将更新間隔時間設定為 n 秒(預設值為 4 秒)

-notile     最初不平鋪顯示視窗(對于兩個或更多連接配接)

-pluginpath 指定 jconsole 用于查找插件的路徑

-version    輸出程式版本

connection = pid || host:port || JMX URL (service:jmx:<protocol>://…)

pid       目标程序的程序 ID

host      遠端主機名或 IP 位址

port      用于遠端連接配接的端口号

-J        對正在運作 jconsole 的 Java 虛拟機指定輸入參數

2.17 jdb

2.18 jhat

2.19 jinfo

2.20 jmap

2.21 jps

列出目前正在運作的Java程式。

Java Virtual Machine Process Status Tool

The jps

command will report the local VM identifier, or lvmid

, for each instrumented JVM found on the target system. The lvmid

is typically, but not necessarily, the operating system’s process identifier for the JVM process.

參數說明:

-q

Suppress the output of the class name, JAR file name, and arguments

passed to the main method, producing only a list of local VM

identifiers.

-m

Output the arguments passed to the main method. The output may be null for embedded JVMs.

-l

Output the full package name for the application’s main class or the full path name to the application’s JAR file.

-v

Output the arguments passed to the JVM.

-V

Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags=<filename

> argument).

-J

option

Pass option

to the java

launcher called by javac

. For example, -J-Xms48m

sets the startup memory to 48 megabytes. It is a common convention for -J

to pass options to the underlying VM executing applications written in Java.

bash-3.2$ jps -help

usage jps [-help]

jps [-q] [-mlvV] [<hostid>]

Definitions

<hostid>      <hostname>[<port>]

bash-3.2$ jps

3080

1100 Jps

bash-3.2$ jps -l

3020

572 sun.tools.jps.Jps

bash-3.2$ jps -v

2744 Jps -Denv.class.path=.;E:/lib;D:/Program Files/Java/jdk1.6.0_10/lib;D:

6.0_10/lib/tools.jar; -Xms8m

3020  -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx256m -XX:MaxPermSize=256M

2.22 jrunscript

bash-3.2$ jrunscript -help

Usage: jrunscript [options] [arguments...]

where [options] include:

-classpath <path>    Specify where to find user class files

-cp <path>           Specify where to find user class files

-D<name>=<value>     Set a system property

-J<flag>             Pass <flag> directly to the runtime system

-l <language>        Use specified scripting language

-e <script>          Evaluate given script

-encoding <encoding> Specify character encoding used by script files

-f <script file>     Evaluate given script file

-f -                 Interactive mode, read script from standard input

If this is used, this should be the last -f option

-help                Print this usage message and exit

-?                   Print this usage message and exit

-q                   List all scripting engines available and exit

If [arguments..] are present and if no -e or -f option is used, then first

argument is script file and the rest of the arguments, if any, are passed

as script arguments. If [arguments..] and -e or -f option is used, then all

[arguments..] are passed as script arguments. If [arguments..], -e, -f are

missing, then interactive mode is used.

bash-3.2$ jrunscript -q

Language ECMAScript 1.6 implemention “Mozilla Rhino” 1.6 release 2

2.23 jstack

Stack Trace

Options are mutually exclusive. Option, if used, should follow immediately after the command name.

prints Java stack traces of Java threads for a given Java process or core file or a remote debug server.

bash-3.2$ jstack -help

Usage:

jstack [-l] <pid>

(to connect to running process)

Options:

-l  long listing. Prints additional information about locks

-h or -help to print this help message

2.24 jstat

Java Virtual Machine Statistics Monitoring Tool

The jstat

tool displays performance statistics for an instrumented HotSpot Java virtual machine (JVM).

command supports two types of options, general options

and output options

. General options cause jstat

to display simple usage and version information. Output options determine the content and format of the statistical output.

bash-3.2$ jstat -help

Usage: jstat -help|-options

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:

<option>      An option reported by the -options option

<vmid>       Virtual Machine Identifier. A vmid takes the following form:

<lvmid>[@<hostname>[:<port>]]

Where <lvmid> is the local vm identifier for the target

Java virtual machine, typically a process id; <hostname> is

the name of the host running the target Java virtual machine;

and <port> is the port number for the rmiregistry on the

target host. See the jvmstat documentation for a more complete

description of the Virtual Machine Identifier.

<lines>       Number of samples between header lines.

<interval>    Sampling interval. The following forms are allowed:

<n>["ms"|"s">

Where <n> is an integer and the suffix specifies the units as

milliseconds(”ms”) or seconds(”s”). The default units are “ms”.

<count>       Number of samples to take before terminating.

-J<flag>      Pass <flag> directly to the runtime system.

bash-3.2$ jstat -options

-class

-compiler

-gc

-gccapacity

-gccause

-gcnew

-gcnewcapacity

-gcold

-gcoldcapacity

-gcpermcapacity

-gcutil

-printcompilation

2560 Jps

2308 JConsole

bash-3.2$ jstat -gcutil -t 2308

Timestamp         S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT

522.9   0.00  91.47   1.88  34.29  72.17     11    0.034     0    0.000    0.034

bash-3.2$ jstat -class -t -h2 2308 500 8[ 間隔500ms運作8次]

Timestamp       Loaded  Bytes  Unloaded  Bytes     Time

1032.7   1634  1977.6        0     0.0       0.40

1033.3   1634  1977.6        0     0.0       0.40

1033.8   1634  1977.6        0     0.0       0.40

1034.3   1634  1977.6        0     0.0       0.40

1034.8   1634  1977.6        0     0.0       0.40

1035.3   1634  1977.6        0     0.0       0.40

1035.8   1634  1977.6        0     0.0       0.40

1036.2   1634  1977.6        0     0.0       0.40

2.25 jstatd

Virtual Machine jstat Daemon

The jstatd

tool is an RMI server application that

monitors for the creation and termination of instrumented HotSpot Java

virtual machines (JVMs) and provides a interface to allow remote

monitoring tools to attach to JVMs running on the local host.

bash-3.2$ jstatd –help

usage: jstatd [-nr] [-p port] [-n rminame]

2.26 jvisualvm

啟動VisualVM檢視VM狀态。

bash-3.2$ jvisualvm &

[1] 3660

2.27 keytool

2.28 kinit

2.29 klist

2.30 ktab

2.31 native2ascii

對檔案轉換編碼。

用法:native2ascii [-reverse] [-encoding 編碼] [輸入檔案 [輸出檔案]]

2.32 orbd

2.33 pack200

2.34 packager

2.35 polocytool

2.36 rmic

2.37 rmid

2.38 rmiregisty

2.39 schemagen

2.40 serialver

2.41 servertool

2.42  tnameserv

2.43  unpack200

2.44  wsgen

2.45  wsimport

2.46  xjc

3、jvm的部分參數

也就是在啟動Java虛拟機、或者執行JAVA時應該添加的程式。

Windows平台下在以下路徑下存在參數說明。

-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              reduce use of OS signals by Java/VM (see documentation)

-Xcheckjni       perform additional checks for JNI functions

-Xshareoff          do not attempt to use shared class data

-Xshareauto      use shared class data if possible (default)

-Xshareon       require using shared class data, otherwise fail.

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

5

、最常用的工具

1)javac Java源代碼編譯工具

6

、部分與優化相關的程式說明