you have to specify the fully qualified package name of the main class in the Main-Class attribute.
try:
Main-Class: hello.HelloWorldSwing


THUFIR HAWAT wrote:

HelloWorldSwing.jar doesn't execute with a double-click, it gives "could not find the main class. program will exit," as an error.

is this a problem with build.xml?

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\Documents and Settings\Administrator>d:

D:\>ant
Buildfile: build.xml

clean:
  [delete] Deleting directory D:\java\classes

prepare:
   [mkdir] Created dir: D:\java\classes

compile:
   [javac] Compiling 1 source file to D:\java\classes

manifest:

package:
     [jar] Building jar: D:\java\classes\HelloWorldSwing.jar

BUILD SUCCESSFUL
Total time: 4 seconds
D:\>type build.xml
<project name="HelloWorldBuild" default="package">

       <property name="outputDir" value="D:\java\classes\" />
       <property name="sourceDir" value="D:\java\src\atreides\hello\" />
       <property name="mainClass" value="HelloWorldSwing" />

       <target name="clean">
               <delete dir="${outputDir}" />
       </target>

       <target name="prepare" depends="clean">
               <mkdir dir="${outputDir}" />
       </target>

       <target name="compile" depends="prepare">
               <javac srcdir="${sourceDir}" destdir="${outputDir}"  />
       </target>

       <target name="manifest" depends="compile">
               <manifest file="${outputDir}/MANIFEST.MF">
                       <attribute name="Main-Class"
                       value="${mainClass}" />
               </manifest>
       </target>

       <target name="package" depends="manifest">
               <jar jarfile="${outputDir}/${mainClass}.jar"
               basedir="${outputDir}"
               manifest="${outputDir}/MANIFEST.MF" />
       </target>
</project>

D:\>cd java\classes\hello

D:\java\classes\hello>dir
Volume in drive D has no label.
Volume Serial Number is 1CBF-03ED

Directory of D:\java\classes\hello

03/14/2005  08:21a      <DIR>          .
03/14/2005  08:21a      <DIR>          ..
03/14/2005  08:21a                 349 HelloWorldSwing$1.class
03/14/2005  08:21a                 897 HelloWorldSwing.class
              2 File(s)          1,246 bytes
              2 Dir(s)   3,585,163,264 bytes free

D:\java\classes\hello>cd ..

D:\java\classes>dir
Volume in drive D has no label.
Volume Serial Number is 1CBF-03ED

Directory of D:\java\classes

03/14/2005  08:21a      <DIR>          .
03/14/2005  08:21a      <DIR>          ..
03/14/2005  08:21a      <DIR>          hello
03/14/2005  08:21a                 135 MANIFEST.MF
03/14/2005  08:21a               1,746 HelloWorldSwing.jar
              2 File(s)          1,881 bytes
              3 Dir(s)   3,585,163,264 bytes free

D:\java\classes>type MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_02-b09 (Sun Microsystems Inc.)
Main-Class: HelloWorldSwing


D:\java\classes>cd ..

D:\java>cd src\atreides\hello

D:\java\src\atreides\hello>dir
Volume in drive D has no label.
Volume Serial Number is 1CBF-03ED

Directory of D:\java\src\atreides\hello

03/14/2005  07:04a      <DIR>          .
03/14/2005  07:04a      <DIR>          ..
03/14/2005  07:26a               1,132 HelloWorldSwing.java
              1 File(s)          1,132 bytes
              2 Dir(s)   3,585,163,264 bytes free

D:\java\src\atreides\hello>type HelloWorldSwing.java
package hello;
import javax.swing.*;

public class HelloWorldSwing {
   /**
    * Create the GUI and show it.  For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    */
   private static void createAndShowGUI() {
       //Make sure we have nice window decorations.
       JFrame.setDefaultLookAndFeelDecorated(true);

       //Create and set up the window.
       JFrame frame = new JFrame("HelloWorldSwing");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       //Add the ubiquitous "Hello World" label.
       JLabel label = new JLabel("Hello World");
       frame.getContentPane().add(label);

       //Display the window.
       frame.pack();
       frame.setVisible(true);
   }

   public static void main(String[] args) {
       //Schedule a job for the event-dispatching thread:
       //creating and showing this application's GUI.
       javax.swing.SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               createAndShowGUI();
           }
       });
   }
}

D:\java\src\atreides\hello>



thanks,

Thufir

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to