How to run a class from a jar with from command-line with classpath specified

后端 未结 2 1928
盖世英雄少女心
盖世英雄少女心 2021-01-22 09:04

I am trying to run a class from a JAR. This class is NOT the only main class in this jar. Also, it requires number of other jar files, which I have kept in the same directory as

相关标签:
2条回答
  • 2021-01-22 09:43

    try:

    java -cp C:\temp\test_myProj\mysql-connector-java-5.1.13-bin.jar;myProjImport.jar com.mycomp.myProj.importer.csv.TestImporter "C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties" "C:\temp\apollo_claims_test.txt"

    provided your running this from the same direcotry as myProjImport.jar

    0 讨论(0)
  • 2021-01-22 09:52

    When -jar option is specified, any other class path options are ignored. So this won't work:

    java -jar MyJar.jar -classpath foo.jar
    

    But if you place foo.jar name into META-INF/manifest.mf within MyJar.jar:

    Class-Path: foo.jar
    

    Then the foo.jar will be searched on the same level as MyJar.jar, i.e. in the same directory.

    Sometimes I just unpack all dependent JARs and pack their content into MyJar.jar. Fewer dependencies this way.

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