Why does my classpath only work with a colon on the end?

扶醉桌前 提交于 2019-12-24 02:58:14

问题


My app only starts logging to log4j if I put a : on the end off the classpath. I already have the properties file and the jar in the classpath, so I'm not sure what's going on. What does ending the classpath with a colon even do? The startup command thus becomes something like this:

java -cp path-to-log4j.properties:bunch:of:other:stuff: app

If I take that last colon off it stops logging, as if it can't find log4j. My question is, what is that last colon actually doing, as in what directory is it adding to the classpath?


回答1:


usually you should put the classpath in quotes -cp "path:path2".

EDIT: The colon might add the current directory.

EDIT2: One cannot add files (except jar files) directly to the classpath. Only directories. Read that today^^




回答2:


Was surprised with similar situation:

Not working:

java -classpath swt.jar org.ivan.swt.SWTHelloWorld

Working:

java -classpath swt.jar: org.ivan.swt.SWTHelloWorld

Also working:

java -classpath :swt.jar org.ivan.swt.SWTHelloWorld

(note colon at the beginning and the end of the swt.jar)

Java(TM) SE Runtime Environment (build 1.8.0_51-b16) on Linux



来源:https://stackoverflow.com/questions/14979328/why-does-my-classpath-only-work-with-a-colon-on-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!