Run java application from command line with external jar files

前端 未结 3 818
青春惊慌失措
青春惊慌失措 2021-01-05 05:27

I have an external jar file(have package structure), which contains the main class, and I can run the app from command line like this:

java -jar example.jar
         


        
相关标签:
3条回答
  • 2021-01-05 06:02

    In Linux System

    Compile and Run Java Program along with External JARs.

    javac -cp </path/jar1>:<path/jar2>:<path/jar3> MainClass.java
    

    If Compiler throws deprecation warning. You can recompile with -Xlint:deprecation argument.

    javac -Xlint:deprecation -cp </path/jar1>:<path/jar2>:<path/jar3> MainClass.java
    

    Finally, run the Java Program:

    java -cp </path/jar1>:<path/jar2>:<path/jar3>:. MainClass
    

    If you want to run Java Process in Background. You can use nohup.

    nohup java -cp </path/jar1>:<path/jar2>:<path/jar3>:. MainClass &
    
    0 讨论(0)
  • 2021-01-05 06:19

    If the class is in bin directory :

    java -cp xxx.jar;bin pck1.pck2.MainClass
    

    If the class is in the current directory :

    java -cp xxx.jar;. pck1.pck2.MainClass
    

    and so on...

    More info in the manual, please read it at least one time... ;-)

    0 讨论(0)
  • 2021-01-05 06:24

    You can use following commands to run java main class or java jar file:

    java -Djava.ext.dirs=E:\lib  E:\Executable\MyMainClass
    
    java -Djava.ext.dirs=E:\lib  E:\Executable\purging.jar
    
    0 讨论(0)
提交回复
热议问题