Methods to detect Java installation and running of jar applications on CentOS

  • 2020-04-01 03:59:09
  • OfStack

Test whether the Java installation configuration is successful

To view the Java version, enter the following command:


[root@dabu.info ~]# java   -version

Create a test Java applet called helloworld.java and type the following command:


[root@dabu.info ~]# touch HelloWorld.java

Copy the following code into helloworld.java:


public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World! This is a test code by nixCraft!");
}
}

After copying in, save the closed file. To compile and run the applet, type the following command:


[root@dabu.info ~]# javac HelloWorld.java
[root@dabu.info ~]# java HelloWorld

The following will be displayed:


Hello, World! This is a test code by nixCraft!

How (how) to run. Jar  This type of Java application?

The syntax is as follows:


[root@dabu.info ~]# java -jar file.jar
[root@dabu.info ~]# java -jar /path/to/my/java/app.jar #/path/to/my/java/app.jar Represents the path of the application 
[root@dabu.info ~]# java -jar /path/to/my/java/app.jar arg1 arg2  # arg1 Said parameters 1  . arg2 Said parameters 2


Related articles: