How to run a java class with a jar in the classpath?

前端 未结 3 1834
轻奢々
轻奢々 2020-11-30 08:27

So, I can do this very well:

java mypackage.MyClass

if ./mypackage/MyClass.class exists. I can also happily do this:



        
3条回答
  •  孤独总比滥情好
    2020-11-30 09:20

    Try this if you're on Windows:

    java -cp .;utilities.jar mypackage.MyClass
    

    Or this if you're on Linux:

    java -cp .:utilities.jar mypackage.MyClass
    

    The current directory is not in the CLASSPATH by default when you specify a value for -cp.

提交回复
热议问题