vscode+java+windows。我想在没有Maven的情况下导入并使用org.apache.logging.log4j.Logger[英] vscode+java+windows: I want to import and use org.apache.logging.log4j.Logger without Maven

本文是小编为大家收集整理的关于vscode+java+windows。我想在没有Maven的情况下导入并使用org.apache.logging.log4j.Logger的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

仅使用添加Java扩展名的VSCODE和本机Java 8,而没有任何其他库或扩展名,我想使用log4j.

我已经下载了各种.jar文件,并且它们在我的类路径中(尽管ClassPath在VSCODE中很难验证,但很高兴能以Vscode IDE验证代码看到的实际路径).这些文件确实显示在左侧资源管理器的" Java依赖项"手风琴菜单下的Vscode中.

3个主文件是:

  • log4j-api2.11.0.jar
  • log4j-core-2.11.0.jar
  • log4j-1.2-api 2.11.0.jar

我有一个启动. 3个主文件.

这些文件实际上位于我的Windows Class Path变量中,并在此中显示.

System.out.println(System.getProperty("java.class.path"));

这显示了到达三个JAR文件位置的字面路径,以及"."的条目,以及它们所在的文件夹(可能过高).

我从VSCODE编辑器收到的错误仍然是

The import org.apache cannot be resolved

在我的代码.java文件中,我有导入,红色的线条在org.apache

import org.apache.logging.log4j.Logger

任何不涉及添加maven的快速修复的建议?

推荐答案

1.请确保您可以创建一个名为lib的文件夹,然后将您的.jar添加到其中

2. .classpath中的配置路径喜欢:

<classpathentry kind="lib" path="lib/log4j-1.2-api-2.11.2.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.11.2.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.11.2.jar"/>

3.如果仍然有错误,请清洁工作区目录:

在这些位置下可以找到VS代码用户工作区存储区域:

  • Windows:%appdata%\代码[ - variant] \ user \ workspacestorage \
  • macOS:$ home/library/应用程序支持/代码[ - variant]/user/workspacestorage/
  • linux:$ home/.config/code [ - variant]/user/workspacestorage/

可以参考

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

问题描述

Using only vscode with java extensions added, and native Java 8 without any additional libraries or extensions, I'd like to use log4j.

I have downloaded the various .jar files and they are in my classpath (although classpath is difficult to verify in vscode, would be nice to have an vscode IDE way to verify the actual path your code sees). The files do show up in vscode under the "JAVA DEPENDENCIES" accordion menu on the left EXPLORER.

The 3 primary .jar files are:

  • log4j-api-2.11.0.jar
  • log4j-core-2.11.0.jar
  • log4j-1.2-api-2.11.0.jar

I have a launch.json file with '"windows": {"classPaths":...' defined and a .classpath file added for good measure with the kind="lib" and the fully qualified literal path given to the 3 primary .jar files.

The files are actually in my Windows CLASSPATH variable and shows up when from within this .java code I execute this line of code:

System.out.println(System.getProperty("java.class.path"));

This shows the literal path to the location of three jar files, as well as an entry for ".", and for the folder that they are in as well (likely overkill).

The error I receive from vscode editor is still

The import org.apache cannot be resolved

in my code's .java file, I have the import, and a red squiggly line is under org.apache

import org.apache.logging.log4j.Logger

Any suggestions of a quick fix that doesn't involve adding Maven?

推荐答案

1.make sure you hava create a folder named lib and add your .jar file into it

2.Configure paths in the .classpath like:

<classpathentry kind="lib" path="lib/log4j-1.2-api-2.11.2.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.11.2.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.11.2.jar"/>

3.if it still thow error,Clean the workspace directory:

the VS Code user workspace storage area can be found under these locations :

  • Windows : %APPDATA%\Code[ - Variant]\User\workspaceStorage\
  • MacOS : $HOME/Library/Application Support/Code[ - Variant]/User/workspaceStorage/
  • Linux : $HOME/.config/Code[ - Variant]/User/workspaceStorage/

could refer to add jar