Setting Java Classpath to Load a Class File

后端 未结 2 760
离开以前
离开以前 2021-02-04 17:50

I\'m new to Java, and I\'m unsure how to access a class file located in a specific directory from a separate program jar.

For example, I have an third party jar file loc

2条回答
  •  感情败类
    2021-02-04 18:02

    In your command line you are trying to run MyClass as a program, which based on your description is not what you want.

    You need to figure out what the main class is that is used to execute the program in the jar. You could unpack the jar file with jar -xf mainprog.jar and look at the META-INF/MANIFEST.MF file. It should have an entry that indicates that the main class of the jar is (I can't remember the name of the entry right now).

    After than change your command line to something like this:

    java -classpath /mainprog.jar:/mylib package.name.to.jar.MainClass
    

提交回复
热议问题