CLASSPATH 中的空格

发布于 2024-09-04 10:43:24 字数 521 浏览 8 评论 0原文

我正在 Windows PC 上工作并且上面有 cygwin! 我已将所有罐子组织在几个目录中的一个目录下! 我正在编写一个 bash 脚本,通过迭代作为参数传递的目录来设置 CLASSPATH ,如下所示:

for JAR_FILE in `ls *.jar`
do
    CLASSPATH="$DIRECTORY_TO_LOOK_FOR_JARS"/$JAR_FILE:$CLASSPATH
done

每当传递的目录中有空格时 < code>/cygdrive/c/Documents and Settings/user/My Jars 并且我运行 java -cp $CLASSPATH somepackage.someclass,它抛出一个错误,指出该类 和找不到,因为 CLASSPATH 变量在 /cygdrive/c/Documents 之后被分割。

有人可以帮我解决这个问题吗?

I am working on a Windows PC and have cygwin on it!
I have organized all my jars under a directory within a few directories!
I am writing a bash script to set the CLASSPATH by iterating through the directory that is passed as a parameter as follows:

for JAR_FILE in `ls *.jar`
do
    CLASSPATH="$DIRECTORY_TO_LOOK_FOR_JARS"/$JAR_FILE:$CLASSPATH
done

Whenever there are spaces in the directory that is passed like /cygdrive/c/Documents and Settings/user/My Jars and I run java -cp $CLASSPATH somepackage.someclass, it throws an error stating that the class and is not found, because the CLASSPATH variable is getting split after /cygdrive/c/Documents.

Can someone help me to solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掌心的温暖 2024-09-11 10:43:24

请参阅这篇文章

您可以将完整的类路径包含在双引号中

java -classpath "C:/Documents and Settings/user/project/lib/axis.jar; C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

,也可以将每个 jar 包含在类路径中。

java -classpath "C:/Documents and Settings/user/project/lib/axis.jar"; "C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

在您的情况下,类似这样的内容:

for JAR_FILE in `ls *.jar`
do
    CLASSPATH="$DIRECTORY_TO_LOOK_FOR_JARS/$JAR_FILE":$CLASSPATH
done

很难看到,但我移动了结束双引号。

See this article.

You could enclose either the full classpath in double qoutes

java -classpath "C:/Documents and Settings/user/project/lib/axis.jar; C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

or each jar in your classpath

java -classpath "C:/Documents and Settings/user/project/lib/axis.jar"; "C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

In your case something like that:

for JAR_FILE in `ls *.jar`
do
    CLASSPATH="$DIRECTORY_TO_LOOK_FOR_JARS/$JAR_FILE":$CLASSPATH
done

Hard to see, but I moved the closing double qoute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文