dnf install java-17-konajdk -y
java -version
openjdk 17.0.3-ga 2022-04-19OpenJDK Runtime Environment TencentKonaJDK (build 17.0.3-ga+1)OpenJDK 64-Bit Server VM TencentKonaJDK (build 17.0.3-ga+1, mixed mode, sharing)
dnf install java-11-konajdk -y
java -version
openjdk 11.0.18-ga 2023-01-17OpenJDK Runtime Environment TencentKonaJDK (build 11.0.18-ga+1)OpenJDK 64-Bit Server VM TencentKonaJDK (build 11.0.18-ga+1, mixed mode, sharing)
dnf install java-8-konajdk -y
java -version
openjdk version "1.8.0_322"OpenJDK Runtime Environment (Tencent Kona 8.0.13) (build 1.8.0_322-1)OpenJDK 64-Bit Server VM (Tencent Kona 8.0.13) (build 25.322-b1, mixed mode, sharing)
alternatives --config java
dnf remove java-17-konajdk-headless -y
dnf remove java-11-konajdk-headless -y
dnf remove java-8-konajdk-headless -y
MyFirstClass.java 如下:public class MyFirstClass {public static void main(String... args) {System.out.println("Hello, World!");}}
java MyFirstClass.java
java -version
dnf install java-17-konajdk-devel
javac MyFirstClass.java
java MyFirstClass
dnf install apache-commons-cli -y
apache-commons-cli 模块包为例。dnf install maven maven-openjdk17 -y
mvn -v
Apache Maven 3.8.6Maven home: /usr/share/mavenJava version: 17.0.3-ga, vendor: Tencent Company, runtime: /usr/lib/jvm/java-17-konajdkDefault locale: zh_CN, platform encoding: UTF-8OS name: "linux", arch: "x86_64", family: "unix"
maven-openjdk 版本不满足需求,需要先卸载当前版本 maven-openjdk,再安装其他版本。mvn archetype:generate -DgroupId=com.testmaven.myfirstapp -DartifactId=myfirstapp -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
myfirstapp 的 maven 项目,同时将自动从 maven 中央仓库下载依赖的插件包,插件包的默认存放位置为 ~/.m2。myfirstapp/├── pom.xml└── src├── main│ └── java│ └── com│ └── testmaven│ └── myfirstapp│ └── App.java└── test└── java└── com└── testmaven└── myfirstapp└── AppTest.java
pom.xml maven 项目配置文件,包含了项目的基本信息、依赖关系、构建方式等。src/main/java 存放项目源码。src/main/java 存放项目测试源码。<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.testmaven.myfirstapp</groupId><artifactId>myfirstapp</artifactId><version>1.0-SNAPSHOT</version><name>myfirstapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies><build><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin>...</plugins></pluginManagement></build></project>
mvn package
[INFO] Scanning for projects...[INFO][INFO] ----------------< com.testmaven.myfirstapp:myfirstapp >-----------------[INFO] Building myfirstapp 1.0-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ myfirstapp ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /home/myfirstapp/src/main/resources...[INFO] -------------------------------------------------------[INFO] T E S T S[INFO] -------------------------------------------------------[INFO] Running com.testmaven.myfirstapp.AppTest[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 s - in com.testmaven.myfirstapp.AppTest[INFO][INFO] Results:[INFO][INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[INFO][INFO][INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ myfirstapp ---[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.197 s[INFO] Finished at: 2023-05-26T11:59:51+08:00[INFO] ------------------------------------------------------------------------
jdb MyFirstClass.java
[root@localhost new]# jdb MyFirstClass.javaInitializing jdb ...> stop in MyFirstClass.mainDeferring breakpoint MyFirstClass.main.It will be set after the class is loaded.> runrun MyFirstClass.javaSet uncaught java.lang.ThrowableSet deferred uncaught java.lang.Throwable>VM Started: Set deferred breakpoint MyFirstClass.mainBreakpoint hit: "thread=main", MyFirstClass.main(), line=4 bci=04 System.out.println("Hello, World!");main[1] where[1] MyFirstClass.main (MyFirstClass.java:4)[2] jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (native method)[3] jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)[4] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)[5] java.lang.reflect.Method.invoke (Method.java:568)[6] com.sun.tools.javac.launcher.Main.execute (Main.java:419)[7] com.sun.tools.javac.launcher.Main.run (Main.java:192)[8] com.sun.tools.javac.launcher.Main.main (Main.java:132)main[1]
stop in 命令在 main 函数处设置断点,然后通过 run 命令运行程序。程序在断点处暂停后,再使用 where 命令打印当前调用栈。更多命令可以通过 jdb 交互界面输入 help 命令查看。文档反馈