Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Jar File Posted by hunny on 20 Dec 2004 at 12:18 AM
hello

I have bundled my application in a jar file
i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method
Report
Re: Jar File Posted by arb123 on 20 Dec 2004 at 10:17 AM
: hello
:
: I have bundled my application in a jar file
: i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method
:

Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file

More info here:
http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html

---------------------------------
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html

Report
Re: Jar File Posted by hunny on 23 Dec 2004 at 12:27 AM
: : hello
: :
: : I have bundled my application in a jar file
: : i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method
: :
:
: Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file
:
: More info here:
: http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html
:
: ---------------------------------
: HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html
:
:
how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file


Report
Re: Jar File Posted by arb123 on 4 Jan 2005 at 3:48 AM
: how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file

The MANIFEST.MF file is a text file. All it needs to contain is the following code and be in the META-INF directory inside the JAR file (which is a ZIP file with a different extension).

Main-Class: mypackage.MyMainClass


---------------------------------
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html

Report
Re: Jar File Posted by hunny on 9 Jan 2005 at 4:20 AM
: : how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file
:
: The MANIFEST.MF file is a text file. All it needs to contain is the following code and be in the META-INF directory inside the JAR file (which is a ZIP file with a different extension).
:
:
: Main-Class: mypackage.MyMainClass
: 

:
: ---------------------------------
: HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html
:
:

sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
plz give me example

Report
Re: Jar File Posted by arb123 on 10 Jan 2005 at 3:50 AM
: sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
: plz give me example

http://java.sun.com/docs/books/tutorial/jar/basics/
http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html

A manifest file is just a text file; for a class:
package mypackage;
public class MyClass {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

You could have a manifest just containing:
Main-Class: mypackage.MyClass

You can use a ZIP application to create a JAR file containing:
META-INF/MANIFEST.MF
mypackage/MyClass.class

This can be executed using the -jar switch:
java -jar myjar.jar


---------------------------------
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html

Report
Re: Jar File Posted by hunny on 11 Jan 2005 at 12:21 AM
: : sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
: : plz give me example
:
: http://java.sun.com/docs/books/tutorial/jar/basics/
: http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html
:
: A manifest file is just a text file; for a class:
:
: package mypackage;
: public class MyClass {
:   public static void main(String[] args) {
:     System.out.println("Hello, World!");
:   }
: }

hi
Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the 
Java virtual Machine Launcher  "Could not find the main class,Program will exit!"
Steps following to create the Jar file are
1)I've created the txt file naming entrypoint class having the following header

Main-Class:   myApplication.mymainclass

2)by the use of following command am creating the Jar file

jar cmf entrypointclass myApplication.jar myApplication

but when i run the jar file on the dos prompt using
java -jar myApplication.jar
the following error is occuring
Exception in thread "main" java.lang.NoClassDefFoundError: amain

Could I have constructed the jar file wrong? 
: 

: You could have a manifest just containing:
:
: Main-Class: mypackage.MyClass
: 

: You can use a ZIP application to create a JAR file containing:
:
: META-INF/MANIFEST.MF
: mypackage/MyClass.class
: 

: This can be executed using the -jar switch:
:
: java -jar myjar.jar
: 

:
: ---------------------------------
: HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html
:
:

Report
Re: Jar File Posted by arb123 on 11 Jan 2005 at 3:03 AM
: Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the
: Java virtual Machine Launcher "Could not find the main class,Program will exit!"

You can list the contents of a JAR file using the command:
jar tf jarfilename.jar


Ensure all the files you wanted to add are present. Class files should be in a directory structure corresponding to their packages.

---------------------------------
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html

Report
Re: Jar File Posted by hunny on 13 Jan 2005 at 3:47 AM
: : Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the
: : Java virtual Machine Launcher "Could not find the main class,Program will exit!"
:
: You can list the contents of a JAR file using the command:
:
: jar tf jarfilename.jar
: 

:
: Ensure all the files you wanted to add are present. Class files should be in a directory structure corresponding to their packages.
:
: ---------------------------------
: HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html
:
:


sir! this all is true for all packaged classes
but what strategy i must atopt when my classes are not packaged


Report
Re: Jar File Posted by arb123 on 13 Jan 2005 at 4:48 AM
Here is an example for creating a JAR file using the GNU ZIP command (available for Win32 from http://unxutils.sourceforge.net/ ).

I have the following files enumerated by the DIR command:
C:\demo1>dir /s /b
C:\demo1\META-INF
C:\demo1\MyClass.class
C:\demo1\MyClass.java
C:\demo1\META-INF\MANIFEST.MF


MANIFEST.MF contents:
Main-Class: MyClass

MyClass.java contents (class has no package declaration; is in the default package):
public class MyClass {
	public static void main(String[] args) {
		System.out.println("Hello, World!");
	}
}


I create the JAR using the ZIP command (you probably don't want the Java source code in it, but it does no harm):
C:\demo1>zip -r ..\myjar.jar *
  adding: META-INF/ (244 bytes security) (stored 0%)
  adding: META-INF/MANIFEST.MF (164 bytes security) (deflated 10%)
  adding: MyClass.class (164 bytes security) (deflated 31%)
  adding: MyClass.java (164 bytes security) (deflated 12%)


This can be run thus:
C:\>java -jar C:\myjar.jar
Hello, World!


---------------------------------
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html




 

Recent Jobs