简体   繁体   English

设置类路径以包含.jar文件

[英]Set classpath to include .jar file

I'm working with JGraphT API and trying to compile and run this demo ( https://raw.githubusercontent.com/jgrapht/jgrapht/master/jgrapht-demo/src/main/java/org/jgrapht/demo/HelloJGraphT.java ). 我正在使用JGraphT API并尝试编译并运行此演示( https://raw.githubusercontent.com/jgrapht/jgrapht/master/jgrapht-demo/src/main/java/org/jgrapht/demo/HelloJGraphT。 java )。

My current directory contains the .java file and the directory called jgrapht-0.9.1. 我当前的目录包含.java文件和名为jgrapht-0.9.1的目录。 jgrapht-0.9.1 contains the folder lib where all the .jar files are. jgrapht-0.9.1包含所有.jar文件所在的文件夹lib。

I've successfully compiled the file using: 我已经使用以下命令成功编译了文件:

javac -cp ./jgrapht-0.9.1/lib/*: HelloJGraphT.java

But I'm having difficulty running the program. 但是我在运行程序时遇到困难。 I have tried: 我努力了:

java -cp ./jgrapht-0.9.1/lib/*: HelloJGraphT
java -cp "./jgrapht-0.9.1/lib/*:" HelloJGraphT
java -cp "./jgrapht-0.9.1/lib/*:." HelloJGraphT

Yet none of them worked. 但是他们都没有工作。 I am really confused about the syntax of classpath, and really appreciate any help! 我对classpath的语法非常困惑,非常感谢您的帮助!

First, you must write the full name of the main class: 首先,必须写出主类的全名:

java -cp "jgrapht-0.9.1/lib/*:." org.jgrapht.demo.HelloJGraphT

Second, I am assuming that the compiled class is in directory structure in the current directory: 其次,我假设编译后的类位于当前目录的目录结构中:

org/jgrapht/demo/HelloJGraphT.class

Third, you must use JDK6 or above in order to use wildcard in classpath. 第三,必须使用JDK6或更高版本才能在类路径中使用通配符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM