Thursday, April 14, 2011

How to get MigLayout to work with my project?

I'm trying to make a small GUI app and I want to use MigLayout with it. As Java newbie I don't know how to get MigLayout to work with my code and I'm running out of ideas.

My project source code is in ~/git/project/src/qdb/

The qdb is my java package name. I downloaded miglayout-3.7-swing.jar and miglayout-3.7.jar and placed them to my project sources and tried to compile the code but I get errors pointing to "new MigLayout()" stating "cannot find symbol".

I was in src dir and used "javac qdb/*.java" to compile (* gets expanded). I also tried to point classpath to my sources like: "javac -classpath /home/user/git/project/src/qdb/ qdb/*.java" but I still get the error.

Then I've also tried to put the jar files to ~/jars/ and use that as classpath but still the same error follows.

So, how to get MigLayout working?

From stackoverflow
  • Simply add the miglayout-3.7-swing.jar to your classpath:

    javac -classpath /your/path/to/miglayout-3.7-swing.jar qdb/*.java
    

    (as illustrating in this thread Installing Mig Layout)


    If you can compile them (with the above line),
    but can not execute the resulting program, you also need to add to the java classpath the library

    java -classpath /your/path/to/miglayout-3.7-swing.jar:/your/project/compiledClass/dir qdb.yourMainClass
    
    Zmyrgel : Also gives same error message.
    VonC : What is the exact command line your are typing ?
    Zmyrgel : Ah, got it to working after deleting the other jar files and trying again. Really should check out ant or something instead of manually typing these commands all the time. Thanks for your help.
    VonC : You are welcome :)
  • If you are going to put it into a .jar file, you'll need to specify the Class-Path in the manifest file:

    Class-Path: /your/path/to/miglayout.jar

  • VonC's answer is right. I just want to add (since you are a Java newbie) that you should consider developing using an IDE. They'll save you hours of by-hand-compiling, and will help you integrate your code with libraries (such as MigLayout) more easily.

    There are two free IDEs I really like:

    IBM's Eclipse.

    SUN's (soon to be IBM's) Netbeans.

    Also consider this SO thread. And this one too.

    Good luck.

0 comments:

Post a Comment