LinuxCommandLibrary

java

Launches a Java application .

TLDR

Execute a java .class file that contains a main method by using just the class name

$ java [classname]
copy


Execute a java program and use additional third-party or user-defined classes
$ java -classpath [path/to/classes1]:[path/to/classes2]:. [classname]
copy


Execute a .jar program
$ java -jar [filename.jar]
copy


Execute a .jar program with debug waiting to connect on port 5005
$ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 -jar [filename.jar]
copy


Display JDK, JRE and HotSpot versions
$ java -version
copy


Display usage information for the java command
$ java -help
copy

Help

Usage: java [options]  [args...] 
           (to execute a class) 
   or  java [options] -jar  [args...] 
           (to execute a jar file) 
   or  java [options] -m [/] [args...] 
       java [options] --module [/] [args...] 
           (to execute the main class in a module) 
   or  java [options]  [args] 
           (to execute a single source-file program) 

 Arguments following the main class, source file, -jar 
 -m or --module / are passed as the arguments to 
 main class. 

 where options include: 

    -cp  
    -classpath  
    --class-path  
                  A : separated list of directories, JAR archives, 
                  and ZIP archives to search for class files. 
    -p  
    --module-path ... 
                  A : separated list of directories, each directory 
                  is a directory of modules. 
    --upgrade-module-path ... 
                  A : separated list of directories, each directory 
                  is a directory of modules that replace upgradeable 
                  modules in the runtime image 
    --add-modules [,...] 
                  root modules to resolve in addition to the initial module. 
                   can also be ALL-DEFAULT, ALL-SYSTEM, 
                  ALL-MODULE-PATH. 
    --list-modules 
                  list observable modules and exit 
    -d  
    --describe-module  
                  describe a module and exit 
    --dry-run     create VM and load main class but do not execute main method. 
                  The --dry-run option may be useful for validating the 
                  command-line options such as the module system configuration. 
    --validate-modules 
                  validate all modules and exit 
                  The --validate-modules option may be useful for finding 
                  conflicts and other errors with modules on the module path. 
    -D= 
                  set a system property 
    -verbose:[class|module|gc|jni] 
                  enable verbose output 
    -version      print product version to the error stream and exit 
    --version     print product version to the output stream and exit 
    -showversion  print product version to the error stream and continue 
    --show-version 
                  print product version to the output stream and continue 
    --show-module-resolution 
                  show module resolution output during startup 
    -? -h -help 
                  print this help message to the error stream 
    --help        print this help message to the output stream 
    -X            print help on extra options to the error stream 
    --help-extra  print help on extra options to the output stream 
    -ea[:...|:] 
    -enableassertions[:...|:] 
                  enable assertions with specified granularity 
    -da[:...|:] 
    -disableassertions[:...|:] 
                  disable assertions with specified granularity 
    -esa | -enablesystemassertions 
                  enable system assertions 
    -dsa | -disablesystemassertions 
                  disable system assertions 
    -agentlib:[=] 
                  load native agent library , e.g. -agentlib:jdwp 
                  see also -agentlib:jdwp=help 
    -agentpath:[=] 
                  load native agent library by full pathname 
    -javaagent:[=] 
                  load Java programming language agent, see java.lang.instrument 
    -splash: 
                  show splash screen with specified image 
                  HiDPI scaled images are automatically supported and used 
                  if available. The unscaled image filename, e.g. image.ext, 
                  should always be passed as the argument to the -splash option. 
                  The most appropriate scaled image provided will be picked up 
                  automatically. 
                  See the SplashScreen API documentation for more information 
    @argument files 
                  one or more argument files containing options 
    -disable-@files 
                  prevent further argument file expansion 
    --enable-preview 
                  allow classes to depend on preview features of this release 
To specify an argument for a long option, you can use --= or 
-- 

Copied to clipboard