在Visual Studio代码,类路径中导入.jar [英] Import .jar in Visual Studio Code, classpath

查看:299
本文介绍了在Visual Studio代码,类路径中导入.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio Code编写Java项目。为此,我想在项目中使用MigLayout.jar。

I am using Visual Studio Code to Write a Java Project. For that i want to use the MigLayout.jar in my Project.

我创建了一个新项目,因此我将获得一个.classpath

I created a new Project so i would get a .classpath

我尝试按照此处的说明进行操作:
https://stackoverflow.com/a/54535301/ 11654683

I tried to follow the instructions here: https://stackoverflow.com/a/54535301/11654683

在这里您可以看到我的类路径文件

Here you can see my Classpath File

<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12"/>
    <classpathentry kind="src" path="src/"/>
    <classpathentry kind="output" path="bin"/>
    <classpathentry exported="true" kind="lib" path="lib/miglayout.jar">
</classpath>

当我尝试编辑类App.java时说:
App.java isnt在类路径
上,将仅报告语法错误。

When I try to edit my class App.java it says: App.java isnt on the classpath Only Syntax errors will be reported.

这是我的java文件的路径:
11-Test Project\Test Project \src\app\app.java

This is the path of my java file: 11 - Test Project\Test Project\src\app\app.java

我确实想继续使用VS Code,而不希望更改为其他编辑器。
我如何才能最终在没有出现这些错误的情况下使用MigLayout.jar?

I do want to continue using VS Code and not change to a different Editor. How can I finally use my MigLayout.jar without getting these errors?

编辑:

我在独立文件旁边创建了一个lib文件夹,并插入了要导入的jar文件。

I created a lib folder next to an independent file and inserted the jar file I wanted to import. VS Code does now understand MigLayout as a type when I import

import net.miginfocom.layout.Grid;现在,VS Code确实将MigLayout理解为一种类型。
import net.miginfocom.swing.MigLayout;

import net.miginfocom.layout.Grid; import net.miginfocom.swing.MigLayout;

但是在编译时显示:
.\Win.java:5:error:package net.miginfocom.layout不存在
import net.miginfocom.layout.Grid;
^
.\Win.java:6:错误:程序包net.miginfocom.swing不存在
import net.miginfocom.swing.MigLayout;

But when compiling it says: .\Win.java:5: error: package net.miginfocom.layout does not exist import net.miginfocom.layout.Grid; ^ .\Win.java:6: error: package net.miginfocom.swing does not exist import net.miginfocom.swing.MigLayout;

如您所见,我已经在浏览器中引用了它:
结构

As you can see i have referenced it in the browser: Structure

推荐答案

1。确保已创建名为 lib的文件夹在项目中,然后将 .jar 文件添加到其中

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

2。在 .classpath 像:

<classpathentry kind="lib" path="lib/miglayout.jar"/>

3。如果仍然出现错误,请清理工作区目录:F1-输入清理-清理工作区

3.if it still thow error,Clean the workspace directory:F1 - input Clean -clean workspace

您可以看一下添加jar

这篇关于在Visual Studio代码,类路径中导入.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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