Friday, November 15, 2013

How to create runnable/executable jar with Eclipse

Assuming I have the following project structure in Eclipse

and following code for RunnableJarFrame.java
package test;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class RunnableJarFrame extends JFrame {

 private static final long serialVersionUID = 1L;
 public static void main(String args[]) {
  new RunnableJarFrame();
 }
 RunnableJarFrame() {
  JLabel jlb = new JLabel("Runnable Test");
  add(jlb);
  this.setSize(200, 100);
  setVisible(true);
 }
}

Steps to export the above project as runnable jar
1. R-click on selected project > Export > Java > Runnable JAR file > Next

2. a) Choose main class from Launch Configuration
    b) Choose Export destination
    c) Finish

3. D-click on the exported jar, the following dialog should appears.


Done!!

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...