为什么我的classpath只在结尾处有一个冒号?[英] Why does my classpath only work with a colon on the end?

本文是小编为大家收集整理的关于为什么我的classpath只在结尾处有一个冒号?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的应用只会开始登录到log4j,如果我将a:在class路径末尾放置.我已经有属性文件和jarpath中的罐子,所以我不确定发生了什么.结束结肠的阶级路径甚至会做什么?因此,启动命令成为这样的东西:

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

如果我将最后一个结肠删除,则停止记录,就好像找不到log4j一样.我的问题是,最后一个结肠实际上在做什么,就像在哪个目录中添加到classpath中?

推荐答案

通常,您应该将classpath放在引号-cp" path:path2".

编辑:结肠可能会添加当前目录.

edit2:一个人无法将文件(JAR文件除外)直接添加到ClassPath.只有目录.今天阅读^^

其他推荐答案

对类似情况感到惊讶:

不工作:

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

工作:

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

也可以工作:

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

(在SWT.Jar的开头和结尾处注意结肠)

java(tm)se运行时环境(构建1.8.0_51-b16)linux

本文地址:https://www.itbaoku.cn/post/1575026.html

问题描述

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?

推荐答案

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^^

其他推荐答案

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

相关标签/搜索