我有一个包含4个类的JAR,每个类都有Main方法.我希望能够根据需要运行其中的每一个.我试图从Linux机器上的命令行运行它.
E.g. The name of my JAR is MyJar.jar
Run Code Online (Sandbox Code Playgroud)
它具有主类的目录结构,如下所示:
com/mycomp/myproj/dir1/MainClass1.class
com/mycomp/myproj/dir2/MainClass2.class
com/mycomp/myproj/dir3/MainClass3.class
com/mycomp/myproj/dir4/MainClass4.class
Run Code Online (Sandbox Code Playgroud)
我知道我可以在我的Manifest文件中指定一个类作为main.但有没有什么方法可以在命令行上指定一些参数来运行我希望运行的任何类?
我试过这个:
jar cfe MyJar.jar com.mycomp.myproj.dir2.MainClass2 com/mycomp/myproj/dir2/MainClass2.class /home/myhome/datasource.properties /home/myhome/input.txt
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
com/mycomp/myproj/dir2/MainClass2.class : no such file or directory
Run Code Online (Sandbox Code Playgroud)
(在上面的命令中,'/ home/myhome/datasource.properties'和'/home/myhome/input.txt'是命令行参数).
我有一个包含两个主要类A类和B类的jar.在清单中我提到了A类.现在我必须从同一个jar中执行classB.什么应该是命令.
我不喜欢做两个独立的罐子.
谢谢