wood burning stoves 2.0*
The moose likes Java in General and the fly likes Problems with aJAR file built using one-jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problems with aJAR file built using one-jar" Watch "Problems with aJAR file built using one-jar" New topic
Author

Problems with aJAR file built using one-jar

Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
I am just learning how to build JAR files...

In the course of my research i found information on here about using one-jar to create executable jar files...

I have that process mastered (more or less) when I invoke the fished jar file it executes but does not invoke the GUI...

This is confusing to me because GUI works just fine when I invoke the program outside of the JAR file.

Any help will be appreciated.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Any errors on the console (screen)? How do you run the jar (command line)? Any dependant jar files you perhaps need to include in the classpath?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
. . . and welcome to the Ranch
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
@Koen, Thank you for your prompt reply.

Any errors on the console (screen)?
There are no errors.

How do you run the jar (command line)?
I am not sure what you are referring to. I use the
procedure that I found on the Scott Tuffs SourceForge page to build the jar file and java -jar Jar File name to execute it.

Any dependent jar files you perhaps need to include in the classpath? No I transfer all of the jar files that I built into the lib directory before I build the jar file. The system jar files ar already on the classpath.

Perhaps I should restart this from the beginning...

I am using one-jar-appgen-0.97 version of one-jar.

I found the instructions for preparing the project using the
Application Generator Approach
section of the site under
Quick Start
.

I have just discovered the
CVS
source download section of the site. While I am waiting on your next reply I will also research that section.

@Campbell Richie, Thank you for the welcome. It is great to be apart of a community where greenhorns like myself are treated with kindness and understanding. I hope in the future I will have knowledge that I can share with others.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
I have taken the liberty of converting all the text to black because some people have difficulty reading colours.
If you are new to .jars, have you read the Java Tutorials section? The command-line approach might be easier than a tool.
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Thank you for converting the color back to black. Frankly I was not sure as to how well that would work out. I will take time to read over that tutorial now. I read over what is listed in the jar section of the oracle site... Alas it confused me!

Thank you for your help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
You’re welcome
How did you get on with the tutorial?
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
It was the same tutorial as i looked at previously (only with a different entry point).

I will make one more attempt after I have caught up on my sleep. Whatever happens with that i will post my results.

If I am still having troubles I will post the entire process that I am using from the tree structure to pertinent source files and jar / java output so that you can see what I am doing (and hopefully what I am doing wrong).

Some additional information about my learning style... I often takes me a little longer to figure something out... But I do figure it out I refer back to my past successes so that I rarely have to ask the same question twice.

Thank you again for your help.

Allan
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Here is where things stand...

The Build tree is:

AdminClient/*.class
JarFiles/*.jar


The AdminClient folder contains:

AdminClient.class
AdminClient.java
ClassicSFBShipEntry.class
ClassicSFBShipEntry.java
MainForm.class
MainForm.class


The JarFiles folder contains:

Dialogs.jar
GlobalConfig.jar
LocalConfig.jar
SupportCode.jar


The Manifext add-on file is:

Class-Path: JarFiles/*.jar
Main-Class: AdminClient.AdminClient


When I use this comand line:

jar cvmf AdminClient.jar AdminClient.MF AdminClient/*.class

I get the following as an error message:

allan@INetMach:~/DevSFB$ jar cvmf AdminClient.jar AdminClient.MF AdminClient/AdminClient
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:406)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:169)
at sun.tools.jar.Main.main(Main.java:1167)


It works when I use this command line:

jar cvef AdminClient.jar AdminClient.AdminClient AdminClient/*.class

But when I go to invoke it using:

java -jar AdminClient.jar


I get:

Exception in thread "main" java.lang.NoClassDefFoundError: AdminClient/AdminClient$1
Caused by: java.lang.ClassNotFoundException: AdminClient.AdminClient$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: AdminClient.AdminClient. Program will exit.

At this point I am totally frustrated with this process.

Any help you can give me will be appreciated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Allan Clapp wrote:allan@INetMach:~/DevSFB$ jar cvmf AdminClient.jar AdminClient.MF AdminClient/AdminClient
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:406)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:169)
at sun.tools.jar.Main.main(Main.java:1167)

The Class-Path entry cannot have wildcards in it. You really must specify all separate JAR files. You must also make sure the lines are of the right length; you will have to add some line breaks and indentation to the Class-Path value.
Lines cannot be any longer than 70 characters. If a single entry would exceed 70 characters, you must add a linebreak at exactly 70 characters and then indent the next line with one single space. Repeat until no line is longer than 70 characters. This may mean that you cut off a JAR file name in the middle, but that's how it works.

Exception in thread "main" java.lang.NoClassDefFoundError: AdminClient/AdminClient$1
Caused by: java.lang.ClassNotFoundException: AdminClient.AdminClient$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: AdminClient.AdminClient. Program will exit.

Your code tries to access class AdminClient.AdminClient$1. That's an anonymous inner class. However, its class file doesn't appear to be in your folder. Try recompiling your class and recreating the JAR file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Thank to Rob's suggestions and tips. I am closer to a solution. My classpath problem seems to be corrected. But the java -jar command is still not finding my entry point.

I am sure the solution is simple I am just not seeing it.

Here is the manifest file I am currently using:

Class-Path: GlobalConfig/GlobalConfig.jar
LocalConfig/LocalConfig.jar Dialogs/Dialogs.jar
SupportCode/SupportCode.jar
Main-Class: AdminClient




Here is the compile commands and output:

javac Dialogs/TheServerConnectionInfoScreen.java
javac GlobalConfig/DomainInfo.java
javac GlobalConfig/UserInfo.java
jar cf GlobalConfig/GlobalConfig.jar GlobalConfig/DomainInfo.class \
GlobalConfig/UserInfo.class
javac LocalConfig/SystemAreaConfig.java
javac LocalConfig/AdminAreaConfig.java
javac LocalConfig/PlayerAreaConfig.java
javac LocalConfig/MonitorAreaConfig.java
javac LocalConfig/ShipAreaConfig.java
javac LocalConfig/AdminUserInfo.java
javac LocalConfig/PlayerUserInfo.java
jar cf LocalConfig/LocalConfig.jar LocalConfig/*.class
javac Dialogs/UserLoginScreen.java
javac Dialogs/AdminUserLoginScreen.java
javac Dialogs/PlayerUserLoginScreen.java
javac Dialogs/UserDefinedErrorMessage.java
javac Dialogs/UserStatusMessage.java
javac Dialogs/ServerConnectionInfoScreen.java
jar cf Dialogs/Dialogs.jar Dialogs/*.class
javac SupportCode/PanelHelper.java
javac SupportCode/ListenerHelper.java
javac SupportCode/MenuItemMouseListener.java
javac SupportCode/ButtonMouseListener.java
javac SupportCode/TextFieldKeyListener.java
javac SupportCode/NewListenerHelper.java
javac SupportCode/LoadListenerHelper.java
javac SupportCode/SaveListenerHelper.java
javac SupportCode/UpdateListenerHelper.java
javac SupportCode/DisplaySSDListenerHelper.java
javac SupportCode/RaceListenerHelper.java
javac SupportCode/ShipTypeListenerHelper.java
javac SupportCode/RefitTypeListenerHelper.java
javac SupportCode/SensorListenerHelper.java
javac SupportCode/ScannerListenerHelper.java
javac SupportCode/DamageControlListenerHelper.java
javac SupportCode/PhasersListenerHelper.java
javac SupportCode/PhotonsListenerHelper.java
javac SupportCode/PlasmasListenerHelper.java
javac SupportCode/PlasmasListenerHelper.java
javac SupportCode/FusionBeamsListenerHelper.java
javac SupportCode/HellboresListenerHelper.java
javac SupportCode/PPDsListenerHelper.java
javac SupportCode/DisruptorsListenerHelper.java
javac SupportCode/ChangeFrameICON.java
jar cf SupportCode/SupportCode.jar SupportCode/*.class
javac AdminClientForms/ClassicSFBShipEntry.java
javac AdminClientForms/MainForm.java
jar cf AdminClientForms/AdminClientForms.jar AdminClientForms/MainForm.class \
AdminClientForms/ClassicSFBShipEntry.class
javac AdminClient.java
jar cmf AdminClient.mf AdminClient.jar AdminClient.class
javac ServerTest/ServerTest.java


And here is what happens when I invoke the jar file:

allan@INetMach:~/DevSFB$ java -jar AdminClient.jar
Exception in thread "main" java.lang.NoClassDefFoundError: AdminClient$1
Caused by: java.lang.ClassNotFoundException: AdminClient$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: AdminClient. Program will exit.


Thank you all in advance for your help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, now you're getting somewhere. If I'm not mistaken then this command:

creates a jar file containing only the single class AdminClient.class, am I right? But your AdminClient class appears to have an anonymous inner class whose name when compiled is AdminClient$1.class, and you aren't including that inner class in this jar or any other, as far as I can see. So try this version instead:
Allan Clapp
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Hi Paul,

No in fact the entry point class is: AdminClient. I was getting the "anonymous inner class" because of attempting to run the jar file when my AdminClient was in a package called
AdminClient
which now it is not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with aJAR file built using one-jar
 
Similar Threads
ejbdeploy.bat help needed
Jars not recognizing in unix
Executable jar files with CLI programs?
Help - Downloaded Jar files
applet invoked from within a jar file