Angelo Lee's Blog
This is my kingdom .If i don't fight for it ,who will ?

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.
[Solaris and Linux ] [Windows ]
javadoc API documentation generator.
See Javadoc Tool page for doclet and taglet APIs.
[Solaris and Linux ] [Windows ]
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. [Solaris and Linux ] [Windows ]
jar Create and manage Java Archive (JAR) files.
See Java Archive Files page for the JAR specification.
[Solaris and Linux ] [Windows ]
jdb The Java Debugger.
See JPDA for the debugger architecture specifications.
[Solaris and Linux ] [Windows ]
javah C header and stub generator. Used to write native methods. [Solaris and Linux ] [Windows ]
javap Class file disassembler [Solaris and Linux ] [Windows ]
extcheck Utility to detect Jar conflicts. [Solaris and Linux ] [Windows ]

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.

Tool Name Brief Description Links to Reference Pages
keytool Manage keystores and certificates. [Solaris and Linux ] [Windows ]
jarsigner Generate and verify JAR signatures. [Solaris and Linux ] [Windows ]
policytool GUI tool for managing policy files. [Solaris and Linux ] [Windows ]

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

Tool Name Brief Description Links to Reference Pages
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 . [Linux ] [Windows ]
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 . [Linux ] [Windows ]

Internationalization Tools

This tool helps to create localizable apps.

Tool Name Brief Description Links to Reference Pages
native2ascii Convert text to Unicode Latin-1. [Solaris and Linux ] [Windows ]

Remote Method Invocation (RMI) Tools

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

Tool Name Brief Description Links to Reference Pages
rmic Generate stubs and skeletons for remote objects. [Solaris and Linux ] [Windows ]
rmiregistry Remote object registry service. [Solaris and Linux ] [Windows ]
rmid RMI activation system daemon. [Solaris and Linux ] [Windows ]
serialver Return class serialVersionUID. [Solaris and Linux ] [Windows ]

Java IDL and RMI-IIOP Tools

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

Tool Name Brief Description
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.

Tool Name Brief Description
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.

Tool Name 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.

Tool Name Brief Description
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 .

Tool Name Brief Description
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 Experimental : JVM Process Status Tool – Lists instrumented HotSpot Java virtual machines on a target system.
jstat Experimental : 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 Experimental : 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 .

Tool Name Brief Description
jinfo Experimental – Configuration Info for Java – Prints configuration information for for a given process or core file or a remote debug server.
jmap Experimental – 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 Experimental – Serviceability Agent Debug Daemon for Java – Attaches to a process or core file and acts as a debug server.
jstack Experimental – 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

bash-3.2$

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();

}

bash-3.2$

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

bash-3.2$

2.23 jstack

Stack Trace

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

jstack 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).

The jstat 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

bash-3.2$ jps

2560 Jps

2308 JConsole

3020

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$

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

Timestamp       Loaded  Bytes  Unloaded  Bytes     Time

1033.8   1634  1977.6        0     0.0       0.40

1034.3   1634  1977.6        0     0.0       0.40

Timestamp       Loaded  Bytes  Unloaded  Bytes     Time

1034.8   1634  1977.6        0     0.0       0.40

1035.3   1634  1977.6        0     0.0       0.40

Timestamp       Loaded  Bytes  Unloaded  Bytes     Time

1035.8   1634  1977.6        0     0.0       0.40

1036.2   1634  1977.6        0     0.0       0.40

bash-3.2$

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

Virtual Machine jstat Daemon

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

2.26 jvisualvm

启动VisualVM查看VM状态。

bash-3.2$ jvisualvm &

[1] 3660

bash-3.2$

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 、部分与优化相关的程序说明

posted on 2010-05-31 09:44  Angelo Lee  阅读(482)  评论(0编辑  收藏  举报