jdk常用命令工具有(jdk怎么用啊)

本文目录
jdk怎么用啊
D:\Java\jdk1.5.0\bin 目录下都是jdk的工具,使用java编程主要用到的是javac.exe、java.exe这两个命令行工具。具体使用步骤如下:
1、配置java系统环境变量:新建文本文件,复制下面代码,然后另存为jdk.bat文件。 @echo setx /M JAVA_HOME "D:\Java\jdk1.5.0" setx /M CLASSPATH ".;%%JAVA_HOME%%\lib;%%JAVA_HOME%%\lib\tools.jar;" setx /M PATH "%PATH%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin;" pause
2、右键以管理员权限打开这个bat文件。
3、编写java代码,新建文本文件,编写一个简单的java程序,然后另存为Hello.java。注意类的名字要和保存的文件名即Hello.java相同。
4、javac Hello.java编译,把.java编译成.class字节码文件,java虚拟机只能运行.class文件。我的Hello.java放在桌面了,所以先要切换下路径cd 你.java文件的路径。
5、java Hello执行,注意后面不要加.java。可以看到输出了hello,表示执行成功了。
使用jdk常用工具排查故障流程
jps定位进程
jstat统计堆信息
jstack定位问题线程
jmap定位问题对象
jps用于查看服务器当前有哪些java进程,排查问题时,一般先使用jps定位到pid
-l参数可以打印完整类路径或jar包路径,-v参数可以打印启动参数
备注: ps -ef | grep java 可以打印启动参数和jar路径,但打印不了类路径
jstat用于统计堆各区域的使用情况等信息
下图中, jstat -gc 1 1000 5 命令表示每1000ms打印一次pid为1的进程的堆的信息,共打印5次。
S0C表示S0的capacity,即总容量,S0U表示S0的used,即已使用空间,单位为kb,U/C可以得到使用率,如MU/MC = 元空间使用率。
E、O、M分别表示Eden区、老年代、元空间,YGC/YGCT表示YGC的GC次数/GC时间,FGC/FGCT表示FGC的GC次数/GC时间。
-gc参数显示具体数值,-gcutil展示比例
jstack用于查看某个进程内的线程信息,常用于排查cpu问题
使用jstack时,一般步骤如下
步骤1,用 top -Hp pid 查看pid进程内的线程的cpu占比,按cpu使用率从大到小排序。
本步骤需要着重观察的是: cpu占比较高的线程,以及cpu运行时间(即TIME+列)较长的线程
这里有一个问题,cpu多高算高?
假设有一个4核的cpu,一个核跑满是100%,整个cpu最高跑到400%。
如果有一个线程死循环(while true),cpu一般能到90%+,到不了100%是因为即使是while true,还是会有时间片轮转。
另外,cpu运行时间也是一个很重要的指标,上图中,pid为71的线程,跑了2小时18分钟,肯定有问题。
步骤2,把当前线程信息导出thread dump文件
步骤3,根据上一步找到的问题线程的pid,把pid转成16进制,因为thread dump文件中,线程pid是用16进制表示的
步骤4,在thread dump文件中检索上一步算出的线程pid的16进制,一般看后20行,能看到完整调用栈即可
可以看到,该线程是kafka消费者线程
注意: 开发时,线程名一定要定好,能对应具体业务,这样用jstack的时候,可以根据线程名马上定位到具体业务。
另外,Thread类的getAllStackTraces方法可以获取当前虚拟机所有线程的调用栈,如果开发人员不方便上生产,可以用该api暴露接口。
jmap用于查看某个进程的对象信息,常用于排查内存问题
jmap -dump:live,format=b,file=/root/1.hprof 1 把堆的内容打印到文件,live参数表示只输出活的对象。
备注:
heap dump文件的大小与当前堆使用量的大小一致,假如堆使用量为2G,heap dump文件就有2G,导出heap dump文件需要很长的时间,导出过程可能会影响对外服务。
另外,heap dump文件只有用专业的工具(如jhat、jvisualvm、mat)才能看,无法用grep等命令检索。
综上,一般很少在生产环境使用该命令。
jmap -histo:live pid 统计类实例数以及字节数。
一般用 jmap -histo:live pid | grep packge 检查是否内存泄漏,page为java项目的包名
jmap -J-D64 -heap 1 打印heap的概要信息
按上面的步骤,一般可以定位到问题,但是比较困难,需要在短时间内做大量操作,因此,推荐使用 阿里的arthas 。
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.
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.
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.
--------------------------------------------------------------------------------
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} 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 秒(默认值为 4 秒)
-notile 最初不平铺显示窗口(对于两个或更多连接)
-pluginpath 指定 jconsole 用于查找插件的路径
-version 输出程序版本
connection = pid || host:port || JMX URL (service:jmx:《protocol》://…)
pid 目标进程的进程 ID
host 远程主机名或 IP 地址
port 用于远程连接的端口号
-J 对正在运行 jconsole 的 Java 虚拟机指定输入参数
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
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
2.26 jvisualvm
启动VisualVM查看VM状态。
bash-3.2$ jvisualvm &
3660
bash-3.2$
2.27 keytool
2.28 kinit
2.29 klist
2.30 ktab
2.31 native2ascii
对文件转换编码。
用法:native2ascii
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 、最常用的工具
javac Java源代码编译工具

更多文章:
elementui 响应式(element-ui 表格元素映射渲染、即 传数字,渲染名称)
2026年9月23日 09:00
python中value函数(python如何无限遍历字典中的value,在不知道字典里面有几层字典的时候)
2026年9月23日 07:10
lenovo是什么梗(为什么有人说联想是美国的求解,这是个什么梗)
2026年9月23日 06:30
FPS是什么 FPS游戏的定义和特点?好玩的FPS单机游戏有哪些
2026年9月23日 04:40






