5

I've been Googling and checking on Stack Overflow and nothing has helped... hopefully someone can.

I usually just write my code by hand, but I'm working on a Java project that has a GUI aspect and I like what MiG Layout has to offer so I want to use it. I've downloaded the .jar file from the website, but I can't seem to be able to access it from my project.

I'm using Eclipse now as my IDE for this project because I don't want to have to deal with this particular thing by hand. I'm new to Eclipse, but here's what I've been trying: import the .jar file (via the Import tool for the project), then add the following code to my files:

import net.miginfocom.swing.MigLayout;
import javax.swing.*;

According to this page, this should work, right?

But when I try to run the program, I'm met with this message:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    MigLayout cannot be resolved to a type

What am I doing wrong?

Josh Leitzel
  • 15,089
  • 13
  • 59
  • 76

1 Answers1

8

It sounds like the "import tool" part didn't work properly - that Eclipse isn't actually using the jar file.

I suggest you right-click on the project, choose Properties, and go to the Build Path page. Look under the "Libraries" tab. Assuming the jar file isn't there, add it and all should be well.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 3
    I am also having this problem . I tried the above steps , it still didn't work for me. – The_Lost_Avatar Oct 11 '13 at 10:37
  • This worked for me: Right-click on the project, choose Build Path, then Configure Build Path. Select the tab Libraries and choose Add External JARs. Add your JAR and select OK :-) – Tia Dec 24 '15 at 14:00
  • @JoshLeitzel Thanks. I used parts of your steps since in the latest version of Eclipse, the UI is not the same as before but still that helped. Thanks! – Tia Dec 24 '15 at 14:05