A newbie question :-)

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
User avatar
Ali Arman Tamal
Learning poster
Posts: 76
Joined: Sat Jan 15, 2005 5:04 pm
Location: Dhaka
Contact:

A newbie question :-)

Post by Ali Arman Tamal » Tue Dec 13, 2005 7:15 am

Hello !

I am doing JAVA in this semester. Can anyone tell me how can i create
a java executable without using batch file. Is it possible ?

How can i hide the console when showing dialog boxes in swing ?

Plz help :D

_____________
Ali Arman Tamal

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Tue Dec 13, 2005 4:04 pm

Java executable? From what I understand the Java compiler from Sun Microsystems does not produce executables but .class files containing bytecode.

From my knowledge of Java, you can compile all your Java source codes using javac *.java.

You might want to look up the asant utility which is similar to make for C/C++ programs.

I am not familiar with swing though.

User avatar
Ali Arman Tamal
Learning poster
Posts: 76
Joined: Sat Jan 15, 2005 5:04 pm
Location: Dhaka
Contact:

Post by Ali Arman Tamal » Tue Dec 13, 2005 4:15 pm

You misunderstood me :-?

I wanted to know is it possible to run java programs with the console
hidden.

thanks :)

User avatar
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post by Cho » Tue Dec 13, 2005 4:21 pm

The jar utility may be what you are looking for: http://java.sun.com/docs/books/tutorial/jar/

Here is a short working example:
Dummy.java:

Code: Select all

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Dummy
{
   public static void main(String[] arg)
   {
      try {
         new DummyFrame().show();
      } catch(Exception x) {
         x.printStackTrace();
      }
   }
}
DummyFrame.java:

Code: Select all

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DummyFrame extends JFrame implements ActionListener
{
   public DummyFrame()
   {
      setTitle("Dummy");
      setSize(320, 240);
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
   }
   
   public void actionPerformed(ActionEvent e)
   {
   }
}
Manifest.txt:

Code: Select all

Main-Class: Dummy
Run these two commands:

Code: Select all

javac *.java
jar cmf Manifest.txt runme.jar *.class
Then, the file runme.jar will be created. Double-clicking it will run the Dummy.class. (If .jar is associated with other program, e.g. winrar, then you should change the association to javaw.)

User avatar
Ali Arman Tamal
Learning poster
Posts: 76
Joined: Sat Jan 15, 2005 5:04 pm
Location: Dhaka
Contact:

Post by Ali Arman Tamal » Tue Dec 13, 2005 4:43 pm

Thanks a lot !
I've found my answer :D :D :D

HolyMoly!!!
New poster
Posts: 2
Joined: Fri Dec 30, 2005 7:18 pm

Post by HolyMoly!!! » Fri Dec 30, 2005 7:44 pm

hello :D

I tried to produce the jar file with the given example. I put the Dummy.java and DummyFrame.java in one folder and also the manifest file in the same folder. Then i applied the command given in that folder path. The jar file was created without any error.

But when i double click to run it (jar file) it says :

"cannot find the main class - program will now exit " :-?

can anyone help me :(

MAK
New poster
Posts: 28
Joined: Sun Oct 23, 2005 3:44 pm
Location: Dhaka, Bangladesh

JAR files

Post by MAK » Sun Jan 01, 2006 11:29 am

Make sure you have included the name of your driver class in the manifest file. The driver class should have have the main method.

Post Reply

Return to “Java”