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

查看:1169
本文介绍了vscode + java + windows:我想在没有Maven的情况下导入并使用org.apache.logging.log4j.Logger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用带有添加的Java扩展的vscode,以及不带任何其他库或扩展的本机Java 8,我想使用log4j.

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

我已经下载了各种.jar文件,它们都在我的类路径中(尽管类路径很难在vscode中进行验证,但是最好有一种vscode IDE方式来验证代码所看到的实际路径).文件确实显示在左侧EXPLORER的"JAVA DEPENDENCIES"手风琴菜单下的vscode中.

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.

3个主要的.jar文件是:

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

我有一个定义为"windows":{"classPaths":...的launch.json文件,并添加了一个.classpath文件以很好地实现,其中带有kind =" lib和给定的完全限定文字路径3个主要的.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.

这些文件实际上位于我的Windows CLASSPATH变量中,并在我执行以下代码行的.java代码中显示:

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"));

这显示了三个jar文件的位置的文字路径,以及."条目以及它们所在的文件夹的条目(可能是过大的杀伤力).

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).

我从vscode编辑器收到的错误仍然存​​在

The error I receive from vscode editor is still

The import org.apache cannot be resolved

在我代码的.java文件中,我已经导入了,并且在org.apache下有一条红色的波浪线

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

关于不涉及添加Maven的快速修复的任何建议吗?

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

推荐答案

1.确保已创建一个名为lib的文件夹,并将.jar文件添加到其中

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

2.在.classpath中配置路径,例如:

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.如果仍然出现错误,请清理工作区目录:

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

可以在以下位置找到VS Code用户工作区存储区域:

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

  • Windows:%APPDATA%\ Code [-变体] \ User \ workspaceStorage \
  • MacOS:$ HOME/库/应用程序支持/代码[- 变体]/用户/工作区存储/
  • Linux:$ HOME/.config/Code [-Variant]/User/workspaceStorage/
  • Windows : %APPDATA%\Code[ - Variant]\User\workspaceStorage\
  • MacOS : $HOME/Library/Application Support/Code[ - Variant]/User/workspaceStorage/
  • Linux : $HOME/.config/Code[ - Variant]/User/workspaceStorage/

可以引用添加jar

这篇关于vscode + java + windows:我想在没有Maven的情况下导入并使用org.apache.logging.log4j.Logger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆