简体   繁体   中英

Import .jar in Visual Studio Code, classpath

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

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

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>

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

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

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?

EDIT:

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; 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.make sure you hava create a folder named lib inside your project and add your .jar file into it

2.Configure paths in the .classpath like:

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

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

you could look at the doucument add jar

I set up a gradle project and added the dependency via the link from https://mvnrepository.com/

I copied the given commands on the MigLayout Site behind the "Gradle" tab and put them into the dependencies{} in the build.grade file

With ./gradlew run from the command line out of the project folder it compiled successfully. Thanks for the help anyways.

PS: I still haven't figured out how to do it without gradle. Even compiling from the command line with: javac -cp "path to jar" myFile i did not get the dependencies right. Let me know if you have experience with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM