Including jars in classpath on commandline (javac or apt)

前端 未结 6 1095
礼貌的吻别
礼貌的吻别 2020-11-22 05:44

trying to run this program. I think that to setup all of the web service stuff I need to run apt. (Although using javac I am having the same issue). I think what I am get

相关标签:
6条回答
  • 2020-11-22 06:16

    Try the following:

    java -cp jar1:jar2:jar3:dir1:. HelloWorld
    

    The default classpath (unless there is a CLASSPATH environment variable) is the current directory so if you redefine it, make sure you're adding the current directory (.) to the classpath as I have done.

    0 讨论(0)
  • 2020-11-22 06:20

    javac HelloWorld.java -classpath ./javax.jar , assuming javax is in current folder, and compile target is "HelloWorld.java", and you can compile without a main method

    0 讨论(0)
  • 2020-11-22 06:21

    Using:

    apt HelloImpl.java -classpath /sac/tools/thirdparty/jaxws-ri/jaxws-ri-2.1.4/lib/jsr181-api.jar:.
    

    works but it gives me another error, see new question

    0 讨论(0)
  • 2020-11-22 06:22

    In windows:

    java -cp C:/.../jardir1/*;C:/.../jardir2/* class_with_main_method
    

    make sure that the class with the main function is in one of the included jars

    0 讨论(0)
  • 2020-11-22 06:28

    Use the -cp or -classpath switch.

    $ java -help  
    Usage: java [-options] class [args...]  
               (to execute a class)  
       or  java [-options] -jar jarfile [args...]  
               (to execute a jar file)  
    
    where options include:  
    ...  
        -cp <class search path of directories and zip/jar files>  
        -classpath <class search path of directories and zip/jar files>  
                      A ; separated list of directories, JAR archives,  
                      and ZIP archives to search for class files.  
    

    (Note that the separator used to separate entries on the classpath differs between OSes, on my Windows machine it is ;, in *nix it is usually :.)

    0 讨论(0)
  • 2020-11-22 06:36

    Note for Windows users, the jars should be separated by ; and not :.

    for example: javac -cp external_libs\lib1.jar;other\lib2.jar;

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