Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 706
Stefan Kablowski Avatar asked Jan 29 '26 08:01

Stefan Kablowski


1 Answers

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

like image 97
Leo Zhu - MSFT Avatar answered Jan 31 '26 20:01

Leo Zhu - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!