File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Once again: Creating a jar-file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Once again: Creating a jar-file" Watch "Once again: Creating a jar-file" New topic
Author

Once again: Creating a jar-file

Wolfgang Troescher
Greenhorn

Joined: Feb 12, 2010
Posts: 14
Hi!

I´m desperating: For hours I´m trying to create a runnable JAR-File, but it doesn´t work. I´v already read a many about this topic in forums and books, but without success.

I create my JAR-file with following command-line:


The JAR-file is created and contains the desired Manifest-file:


Well.. seems everything is all right. But if I double-click on it: "Could not find the main class". But the Main-Class is all right!

If I try to start the programm with

the programm starts successfully!

Strange: Another program I wrote starts successfully by doubleclick on the generated JAR-file, which was created in nearly the same way....
Can you help me?

Thank you
Wolfgang
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Add an empty line at the bottom of the manifest file, and see if it works then.

The tutorial warns about this:
Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Wolfgang Troescher
Greenhorn

Joined: Feb 12, 2010
Posts: 14
Jesper de Jong wrote:Add an empty line at the bottom of the manifest file, and see if it works then.

The tutorial warns about this:
Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


An empty line is there! And I didn´t use Windows-Notepad, but Notepad++ to get right new-line-codes...

And: my manifest-file is properly included!
Wolfgang Troescher
Greenhorn

Joined: Feb 12, 2010
Posts: 14
Wolfgang Troescher wrote:
Jesper de Jong wrote:Add an empty line at the bottom of the manifest file, and see if it works then.

The tutorial warns about this:
Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


An empty line is there! And I didn´t use Windows-Notepad, but Notepad++ to get right new-line-codes...

And: my manifest-file is properly included!


Problem solved: I removed the "dot" from the end of the line:



to


Now it works fine. But... I don´t know why...

No... it still DOESN´T WORK
Doubleclick on JAR started program, but just if the directories with class-files are there! If I remove them: doesn´t start...

Wolfgang
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

CLASS-PATH should be Class-Path.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

You can use the 't' option of the jar command to see what the structure of the jar file is (what files and directories are in there).

What output exactly do you get when you type in a command like this: jar tvf InfoScreenManager.jar
Wolfgang Troescher
Greenhorn

Joined: Feb 12, 2010
Posts: 14
Jesper de Jong wrote:You can use the 't' option of the jar command to see what the structure of the jar file is (what files and directories are in there).

What output exactly do you get when you type in a command like this: jar tvf InfoScreenManager.jar


Hi!

I unzipped the jar-file to see what files are in it. It seems everything o.k.! The path-structure of the package is there with all .class-files in it, the META-INF-directory with MANIFEST.MF, containing correct hint to the main-class ("Main-Class: foo.bar.MyMainClass").

If I try to start programm by double-click on XP: Nothings happens. With Win7 error-message appears ("Could not find the main class"). Frustrating!!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

javaw.exe, the application used to launch JAR files, has rubbish error handling. Any Throwable thrown from the main method is displayed as that rubbish error message. Open a command prompt and run the JAR file as follows, and see what error message it actually prints out:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Once again: Creating a jar-file
 
Similar Threads
What is the easiest wat to open a JAR file?
Setting an Entry Point with JAR Tool
Game Tutorials -->> Creating An Executable JAR File
*.jar files
How to make jar file executeable ?