How to run a jar file in a linux commandline

前端 未结 6 1953
野趣味
野趣味 2021-01-30 08:44

How to set the classpath to the current directory and also run the jar file named load.jar present in the current directory by providing the argument as load=

相关标签:
6条回答
  • 2021-01-30 08:52

    For example to execute from terminal (Ubuntu Linux) or even (Windows console) a java file called filex.jar use this command:

    java -jar filex.jar

    The file will execute in terminal.

    0 讨论(0)
  • 2021-01-30 08:54

    Under linux there's a package called binfmt-support that allows you to run directly your jar without typing java -jar:

    sudo apt-get install binfmt-support
    chmod u+x my-jar.jar
    ./my-jar.jar # there you go!
    
    0 讨论(0)
  • 2021-01-30 08:55

    For OpenSuse Linux, One can simply install the java-binfmt package in the zypper repository as shown below:

    sudo zypper in java-binfmt-misc
    chmod 755 file.jar
    ./file.jar
    
    0 讨论(0)
  • 2021-01-30 09:05

    Running a from class inside your JAR file load.jar is possible via

    java -jar load.jar
    

    When doing so, you have to define the application entry point. Usually this is done by providing a manifest file that contains the Main-Class tag. For documentation and examples have a look at this page. The argument load=2 can be supplied like in a normal Java applications:

    java -jar load.jar load=2
    

    Having also the current directory contained in the classpath, required to also make use of the Class-Path tag. See here for more information.

    0 讨论(0)
  • 2021-01-30 09:10

    copy your file in linux Java directory

    cp yourfile.jar /java/bin
    

    open the directory

    cd /java/bin
    

    and execute your file

    ./java -jar yourfile.jar

    or all in one try this command:

    /java/bin/java -jar jarfilefolder/jarfile.jar

    0 讨论(0)
  • 2021-01-30 09:12
    sudo -sH
    java -jar filename.jar
    

    Keep in mind to never run executable file in as root.

    0 讨论(0)
提交回复
热议问题