Newbie Question Compiling App

I have created a very simple test application to display Hello World in a form.  The code is as follows:

import javax.swing.*;

/**
* Created by Ian on 4/30/14.
*/
public class Test {
    private JPanel panel1;

    public static void main(String[] args) {
        JFrame frame = new JFrame("Test");
        frame.setContentPane(new Test().panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}

the form is


hello world.tiff

This works fine in the IDE so I tried creating a jar file using an arcive in the project structure and then building it. The manifest file created looks like

Manifest-Version: 1.0
Class-Path: ./Test.jar
Main-Class: Test



The app will not run from my mac desktop or terminal program.  Getting a class not found message in the terminal

Can someone please point me in the right direction?
8 comments

Hello.

> Getting a class not found message in the terminal
And what is the name of not found class?

Regards,
Alexander.

0

Error: Could not find or load main class test.jar

0

Thank you. Then I expect you start java with wrong option. Please try:
> java -jar test.jar

Please comment if more problems occur, they are still possible.
Alexander.

0

Getting the following error

Exception in thread "main" java.lang.NoClassDefFoundError: com/jgoodies/forms/layout/FormLayout
 at Test.$$$setupUI$$$(Test.java)
 at Test.<init>(Test.java:6)
 at Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: com.jgoodies.forms.layout.FormLayout
 at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

 ... 3 more


I think this means that it is not finding the JGoodies library.  Is that a claspath issue?
0

Yes, you need to add a jar with FormLayout (et all) to your classpath.

Alexander.

0

Okay.  Thanks so much for your help.

I come to Java and the IntelliJ IDE from the c++ world.  I am used to the IDE creating the basic makefile that if necessary registers the appropriate components.  i.e the equivalent of adding the classpath for you.  Inetliij does not do this for you?

0

Quite natural question. In Java there are several kinds of makefile analogs. There is a lot of information to read, I'll point just to basic directions to investigate.

1. For quick ad-hoc configuration you can check Project Structure dialog / Artifacts section, and configure a jar artifact. This is IDEA-specific, you can't (to my knowledge) use or automatically convert this artifact definition to other IDEs like Eclipse. It is probably Ok for small "hello-world" applications.

2. More universal solution is to use some popular third-party dependency management tool, independent from IDE, and use IDE integration with that tool.
This integration typically includes some actions to generate necessary tool-specific files, or import these files and build IDEA project from them.

2.1. Most popular tool is probably Maven: http://maven.apache.org/
And this is the docs on our integration with it: http://www.jetbrains.com/idea/webhelp/maven.html

2.2. Old tool is Ant: http://ant.apache.org/
But it is now considered obsolete.

2.3. There are also Groovy-based tools Gant and Gradle. I'm not very familiar with them. AFAIK, they are Ok nowadays, just less ubiquitous than Maven.

Regards,
Alexander.

0

Thanks.  Trying Maven out. (Don't seem to be able to mark this thread as answered.)

0

Please sign in to leave a comment.