Including all the jars in a directory within the Java classpath

前端 未结 24 3560
鱼传尺愫
鱼传尺愫 2020-11-21 04:25

Is there a way to include all the jar files within a directory in the classpath?

I\'m trying java -classpath lib/*.jar:. my.package.Program and it is no

24条回答
  •  天命终不由人
    2020-11-21 05:12

    To whom it may concern,

    I found this strange behaviour on Windows under an MSYS/MinGW shell.

    Works:

    $ javac -cp '.;c:\Programs\COMSOL44\plugins\*' Reclaim.java
    

    Doesn't work:

    $ javac -cp 'c:\Programs\COMSOL44\plugins\*' Reclaim.java
    javac: invalid flag: c:\Programs\COMSOL44\plugins\com.comsol.aco_1.0.0.jar
    Usage: javac  
    use -help for a list of possible options
    

    I am quite sure that the wildcard is not expanded by the shell, because e.g.

    $ echo './*'
    ./*
    

    (Tried it with another program too, rather than the built-in echo, with the same result.)

    I believe that it's javac which is trying to expand it, and it behaves differently whether there is a semicolon in the argument or not. First, it may be trying to expand all arguments that look like paths. And only then it would parse them, with -cp taking only the following token. (Note that com.comsol.aco_1.0.0.jar is the second JAR in that directory.) That's all a guess.

    This is

    $ javac -version
    javac 1.7.0
    

提交回复
热议问题