简体   繁体   English

Java在bash中设置类路径

[英]Java setting classpath in bash

I've been having some trouble setting -classpath properly to get a project to run: 我在正确设置-classpath来运行项目时遇到了一些麻烦:

What I thought I was supposed to do: 我以为应该做的事情:

java -classpath /path/to/classes package.Main

The only thing so far that works: 到目前为止,唯一有效的方法是:

cd /path/to/classes
java -classpath . package.Main

I've also tried to do -classpath /path/to/classes:. 我也尝试过-classpath /path/to/classes:.

I need to be able to run that class from different directories so I can't use the solution that did work for me. 我需要能够从不同目录运行该类,所以我不能使用对我有用的解决方案。

I am obviously missing something really stupid here. 我显然在这里缺少真正愚蠢的东西。

EDIT: I am using cygwin 编辑:我正在使用cygwin

The problem was the way classpath is handled in cygwin: 问题是在cygwin中处理类路径的方式:

Since java is a windows program it doesn't recognize the cygwin path I gave. 由于java是Windows程序,因此无法识别我给出的cygwin路径。

The fix was: 解决方法是:

java -classpath `cygpath -wp /path/to/classes/` package.Main

Hope it helps someone else. 希望它可以帮助别人。

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

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