有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java运行*。jar文件与其他文件有一些依赖关系*。使用cmd的jar文件

我在路径中有Java程序:C:\...\MyProgram。 此程序与其他程序有一些依赖关系*。jar文件。我会用cmd运行它。所以我要做的是:

在cmd中我写cd C:\...\MyProgram\bin,然后写java -cp C:\...\MyProgram\*;. main.Main。它正在发挥作用。但现在我将MyProgram导出到jar文件。你能告诉我现在该怎么办吗?所以我有我的程序文件。jar具有这些相同的依赖项。如何使用cmd运行它


共 (2) 个答案

  1. # 1 楼答案

    Folders and archive files

    When classes are stored in a directory (folder), like /java/MyClasses/utility/myapp, then the class path entry points to the directory that contains the first element of the package name. (in this case, /java/MyClasses, since the package name is utility.myapp.)

    But when classes are stored in an archive file (a .zip or .jar file) the class path entry is the path to and including the .zip or .jar file. For example, to use a class library that is in a .jar file, the command would look something like this:

    % java -classpath /java/MyClasses/myclasses.jar utility.myapp.Cool

    发现于http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/classpath.html

  2. # 2 楼答案

    classpath中设置JAR文件的路径,然后执行另一个JAR文件

    使用eclipse添加JAR

    1. 右键单击project->;房产

    2. Java Build Path->;单击添加外部罐子

    3. 这将把JAR添加到类路径中

    enter image description here