Setting an Application's Entry Point

M

mathieu

Hi there

I am reading:

http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

But I still do not understand how to write my Manifest.txt file. In
the end I am getting the following jar file:

$ jar tvf /usr/lib/DICOMscope.jar | grep DICOMscope.class
7272 Mon Dec 29 12:17:44 CET 2008 DICOMscope/DICOMscope/
DICOMscope.class

$ cat DICOMscope.java
package DICOMscope
....
public class DICOMscope extends JFrame implements MainListener
{
public static void main (String[] args)
{
}
}

Compilation line:

$ javac -classpath . -d ../DICOMscope DICOMscope.java
$ cd ../
$ jar cfm DICOMscope.jar Manifest.txt DICOMscope/

How do I say the main function is in class DICOMscope (I do not
understand why my jar file has two levels of DICOMscope).

Thanks.
 
R

RedGrittyBrick

mathieu said:
Hi there

I am reading:

http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

But I still do not understand how to write my Manifest.txt file. In
the end I am getting the following jar file:

$ jar tvf /usr/lib/DICOMscope.jar | grep DICOMscope.class
7272 Mon Dec 29 12:17:44 CET 2008 DICOMscope/DICOMscope/
DICOMscope.class

$ cat DICOMscope.java
package DICOMscope
...
public class DICOMscope extends JFrame implements MainListener
{
public static void main (String[] args)
{
}
}

Compilation line:

$ javac -classpath . -d ../DICOMscope DICOMscope.java
$ cd ../
$ jar cfm DICOMscope.jar Manifest.txt DICOMscope/

How do I say the main function is in class DICOMscope (I do not
understand why my jar file has two levels of DICOMscope).

Thanks.

Sigh!

-----------------------------------------------------
C:\temp>mkdir com

C:\temp>cd com

C:\temp\com>mkdir example

C:\temp\com>cd example

C:\temp\com\example>mkdir dicomscope

C:\temp\com\example>cd dicomscope

C:\temp\com\example\dicomscope>edit DICOMscope.java

C:\temp\com\example\dicomscope>type DICOMscope.java
package com.example.dicomscope;

class DICOMscope {
public static void main(String[] args) {
System.out.println("Hello from DICOMscope");
}
}

C:\temp\com\example\dicomscope>javac DICOMscope.java

C:\temp\com\example\dicomscope>dir
Volume in drive C is OS
Volume Serial Number is 50F9-F19C

Directory of C:\temp\com\example\dicomscope

29/12/2008 11:42 <DIR> .
29/12/2008 11:42 <DIR> ..
29/12/2008 11:42 458 DICOMscope.class
29/12/2008 11:42 157 DICOMscope.java
2 File(s) 615 bytes
2 Dir(s) 48,488,181,760 bytes free

C:\temp\com\example\dicomscope>cd ..\..

C:\temp\com>cd ..

C:\temp>java com.example.dicomscope.DICOMscope
Hello from DICOMscope

C:\temp>edit dicomscope.manifest

C:\temp>type dicomscope.manifest
Main-Class: com.example.dicomscope.DICOMscope

C:\temp>jar cfm DICOMscope.jar dicomscope.manifest com\example\dicomscope

C:\temp>jar tvf DICOMscope.jar
0 Mon Dec 29 11:49:00 GMT 2008 META-INF/
118 Mon Dec 29 11:49:00 GMT 2008 META-INF/MANIFEST.MF
0 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/
458 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/DICOMscope.class
157 Mon Dec 29 11:42:02 GMT 2008 com/example/dicomscope/DICOMscope.java

C:\temp>java -jar DICOMscope.jar
Hello from DICOMscope
 
M

mathieu

mathieu said:
I am reading:

But I still do not understand how to write my Manifest.txt file. In
the end I am getting the following jar file:
$ jar tvf /usr/lib/DICOMscope.jar | grep DICOMscope.class
7272 Mon Dec 29 12:17:44 CET 2008 DICOMscope/DICOMscope/
DICOMscope.class
$ cat DICOMscope.java
package DICOMscope
...
public class DICOMscope extends JFrame implements MainListener
{
public static void main (String[] args)
{
}
}
Compilation line:
$ javac -classpath . -d ../DICOMscope DICOMscope.java
$ cd ../
$ jar cfm DICOMscope.jar Manifest.txt DICOMscope/
How do I say the main function is in class DICOMscope (I do not
understand why my jar file has two levels of DICOMscope).

Sigh!

-----------------------------------------------------
C:\temp>mkdir com

C:\temp>cd com

C:\temp\com>mkdir example

C:\temp\com>cd example

C:\temp\com\example>mkdir dicomscope

C:\temp\com\example>cd dicomscope

C:\temp\com\example\dicomscope>edit DICOMscope.java

C:\temp\com\example\dicomscope>type DICOMscope.java
package com.example.dicomscope;

class DICOMscope {
public static void main(String[] args) {
System.out.println("Hello from DICOMscope");
}

}

C:\temp\com\example\dicomscope>javac DICOMscope.java

C:\temp\com\example\dicomscope>dir
Volume in drive C is OS
Volume Serial Number is 50F9-F19C

Directory of C:\temp\com\example\dicomscope

29/12/2008 11:42 <DIR> .
29/12/2008 11:42 <DIR> ..
29/12/2008 11:42 458 DICOMscope.class
29/12/2008 11:42 157 DICOMscope.java
2 File(s) 615 bytes
2 Dir(s) 48,488,181,760 bytes free

C:\temp\com\example\dicomscope>cd ..\..

C:\temp\com>cd ..

C:\temp>java com.example.dicomscope.DICOMscope
Hello from DICOMscope

C:\temp>edit dicomscope.manifest

C:\temp>type dicomscope.manifest
Main-Class: com.example.dicomscope.DICOMscope

C:\temp>jar cfm DICOMscope.jar dicomscope.manifest com\example\dicomscope

C:\temp>jar tvf DICOMscope.jar
0 Mon Dec 29 11:49:00 GMT 2008 META-INF/
118 Mon Dec 29 11:49:00 GMT 2008 META-INF/MANIFEST.MF
0 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/
458 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/DICOMscope.class
157 Mon Dec 29 11:42:02 GMT 2008 com/example/dicomscope/DICOMscope.java

C:\temp>java -jar DICOMscope.jar
Hello from DICOMscope

No... I still do not get it...

$ cat Manifest.txt
Main-Class: DICOMscope.DICOMscope.DICOMscope

$ java -jar /usr/lib/DICOMscope.jar
Exception in thread "main" java.lang.NoClassDefFoundError: DICOMscope/
DICOMscope/DICOMscope (wrong name: DICOMscope/DICOMscope)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:
260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)


$ jar xvf /usr/lib/DICOMscope.jar | grep "DICOMscope\.class"
inflated: DICOMscope/DICOMscope/DICOMscope.class
 
E

Ewald Ertl

Hi,

mathieu said:
Hi there
 I am reading:
 http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html
  But I still do not understand how to write my Manifest.txt file. In
the end I am getting the following jar file:
$ jar tvf /usr/lib/DICOMscope.jar | grep DICOMscope.class
  7272 Mon Dec 29 12:17:44 CET 2008 DICOMscope/DICOMscope/
DICOMscope.class
$ cat DICOMscope.java
package DICOMscope
...
public class DICOMscope extends JFrame implements MainListener
{
public static  void main (String[] args)
    {
    }
}
Compilation line:
$ javac -classpath . -d ../DICOMscope DICOMscope.java
$ cd ../
$ jar cfm DICOMscope.jar Manifest.txt DICOMscope/
How do I say the main function is in class DICOMscope (I do not
understand why my jar file has two levels of DICOMscope).
Thanks.
C:\temp>cd com
C:\temp\com>mkdir example
C:\temp\com>cd example
C:\temp\com\example>mkdir dicomscope
C:\temp\com\example>cd dicomscope
C:\temp\com\example\dicomscope>edit DICOMscope.java
C:\temp\com\example\dicomscope>type DICOMscope.java
package com.example.dicomscope;
class DICOMscope {
   public static void main(String[] args) {
     System.out.println("Hello from DICOMscope");
   }

C:\temp\com\example\dicomscope>javac DICOMscope.java
C:\temp\com\example\dicomscope>dir
  Volume in drive C is OS
  Volume Serial Number is 50F9-F19C
  Directory of C:\temp\com\example\dicomscope
29/12/2008  11:42    <DIR>          .
29/12/2008  11:42    <DIR>          ..
29/12/2008  11:42               458 DICOMscope.class
29/12/2008  11:42               157 DICOMscope.java
                2 File(s)            615 bytes
                2 Dir(s)  48,488,181,760 bytes free
C:\temp\com\example\dicomscope>cd ..\..
C:\temp\com>cd ..
C:\temp>java com.example.dicomscope.DICOMscope
Hello from DICOMscope
C:\temp>edit dicomscope.manifest
C:\temp>type dicomscope.manifest
Main-Class: com.example.dicomscope.DICOMscope
C:\temp>jar cfm DICOMscope.jar dicomscope.manifest com\example\dicomscope
C:\temp>jar tvf DICOMscope.jar
      0 Mon Dec 29 11:49:00 GMT 2008 META-INF/
    118 Mon Dec 29 11:49:00 GMT 2008 META-INF/MANIFEST.MF
      0 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/
    458 Mon Dec 29 11:42:38 GMT 2008 com/example/dicomscope/DICOMscope.class
    157 Mon Dec 29 11:42:02 GMT 2008 com/example/dicomscope/DICOMscope.java
C:\temp>java -jar DICOMscope.jar
Hello from DICOMscope
---------------------------------------------------------------
Watch out for line-wrap in the first jar command and output of the second.

No... I still do not get it...

$ cat Manifest.txt
Main-Class: DICOMscope.DICOMscope.DICOMscope

$ java -jar /usr/lib/DICOMscope.jar
Exception in thread "main" java.lang.NoClassDefFoundError: DICOMscope/
DICOMscope/DICOMscope (wrong name: DICOMscope/DICOMscope)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:
260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)

$ jar xvf /usr/lib/DICOMscope.jar | grep "DICOMscope\.class"
 inflated: DICOMscope/DICOMscope/DICOMscope.class

I've not used the manifest, but reading the exception and your
manifest file as you wrote:

In DICOMscope.java, you're package statement lists DICOMscope and not
DICOMscope.DICOMscope,
as you request in the manifest file.

I think this is could be the problem.

HTH
Ewald
 
L

Lew

Ewald said:
I've not used the manifest, but reading the exception and your
manifest file as you wrote:

In DICOMscope.java, you're package statement lists DICOMscope and not
DICOMscope.DICOMscope,
as you request in the manifest file.

I think this is could be the problem.

In addition to what Ewald said, it is conventional to name packages
with lower-case letters only, thus making it easier to distinguish
them from class names.

In another thread a poster provided a link to the tutorial on
packages. It is important to understand how to specify and use
packages in Java if one is to do any programming in it whatsoever.

RedGrittyBrick's post shows in detail how to compile and JAR a class
into the correct location for its package. But really, the tutorial
is the place to start.
 
L

Lew

Maybe because the file isn't called "Manifest.txt" but "MANIFEST.MF".

This is totally irrelevant. The 'jar' command should do the right
thing with any named input file for the manifest, creating META-INF/
MANIFEST.MF as required. Sorry about that.
<http://java.sun.com/docs/books/tutorial/deployment/jar/
manifestindex.html>

This is totally right.

<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#JAR
%20Manifest>
<http://java.sun.com/javase/6/docs/technotes/tools/solaris/jar.html>
<http://java.sun.com/javase/6/docs/technotes/tools/windows/jar.html>
<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html>
tell more.
 
R

Roedy Green

How do I say the main function is in class DICOMscope (I do not
understand why my jar file has two levels of DICOMscope).

Normally you let ANT create the manifests for you.

See http://mindprod.com/jgloss/ant.html
see http://mindprod.com/jgloss/jar.html#MANIFEST
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 
M

mathieu

Ewald Ertl wrote:
RedGrittyBrick's post shows in detail how to compile and JAR a class
into the correct location for its package. But really, the tutorial
is the place to start.

Indeed rereading it I finally found the right combo. I have packaged
my very first jar: dicomscope !

Ref:
http://svn.debian.org/viewsvn/debian-med/trunk/packages/dicomscope/trunk/debian/

Working directory for javac is actually very important. Calling the
file Manifest.txt is perfectly fine (at least for me). And sun-java
does not support "default package" as mentionned earlier (gcc-java
does however).


Thanks everybody !
 
A

Andrew Thompson

...I have packaged
my very first jar: dicomscope !
Congrats!

... Calling the
file Manifest.txt is perfectly fine (at least for me).

Wish I had 1$ for every time I heard "Works fine for me" ..and 10$ for
every time that same thing came back to bite the developer on the
a**. ;-)
 
R

Roedy Green

In DICOMscope.java, you're package statement lists DICOMscope and not
DICOMscope.DICOMscope,
as you request in the manifest file.

If you following the naming convention of all lower case for package
names and camel case for class names, that sort of error will tend to
jump out at you.
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top