无法从CLASSPATH导入log4j。

huangapple 未分类评论44阅读模式
英文:

Can not import log4j from CLASSPATH

问题

我正在使用Linux,并且在一个目录中有以下文件:

  1. logtest.java
  2. log4j2.xml
  3. log4j-api-2.13.1.jar
  4. log4j-core-2.13.1.jar

在logtest.java文件中,我使用以下行导入了log4j库:

import org.apache.logging.log4j.*;

我的CLASSPATH是/path/to/directory:/path/to/directory/log4j-api-2.13.1.jar:/path/to/directory/log4j-core-2.13.1.jar

当我执行javac logtest.java时,我得到以下错误:
error: package org.apache.logging.log4j does not exist

但是,当我执行javac -cp /path/to/directory:/path/to/directory/log4j-api-2.13.1.jar:/path/to/directory/log4j-core-2.13.1.jar logtest.java,它可以工作。

为什么在没有-cp参数和CLASSPATH的情况下无法找到该包?

英文:

I am using linux and I have the following files in a directory:

  1. logtest.java
  2. log4j2.xml
  3. log4j-api-2.13.1.jar
  4. log4j-core-2.13.1.jar

In the logtest.java file, I am importing the log4j library with this line:

import org.apache.logging.log4j.*;

My CLASSPATH is /path/to/directory:/path/to/directory/log4j-api-2.13.1.jar:/path/to/directory/log4j-core-2.13.1.jar .

When I execute javac logtest.java, I get the following error:
error: package org.apache.logging.log4j does not exist.

But when I execute javac -cp /path/to/directory:/path/to/directory/log4j-api-2.13.1.jar:/path/to/directory/log4j-core-2.13.1.jar logtest.java, it works.

Why is it unable to find the package without the -cp argument and from the CLASSPATH?

huangapple
  • 本文由 发表于 2020年4月10日 23:33:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/61143579.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定