Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

merg a text file into manifest

Posted on 2003-03-02
12
Medium Priority
?
314 Views
Last Modified: 2010-05-18
I created a text file with notpad and named it mainClass.txt and saved it in Unicode it reads:

 Main-Class: KathySaver

I can not get it to merge into the manifest header using this code:
jar cmf mainClass kathysaver *.class
I tryed writing the full path:
jar cmf C:\KathySaver\mainClass kathysaver *.class
error says it cannot find the file mainClass if I add the .txt extention "mainClass.txt" I get no error but it doesnt change the manifest. I am very stuck on trying to write this line into the manifest header of the jar file
0
Comment
Question by:jayirvin
  • 7
  • 5
12 Comments
 

Expert Comment

by:coljac
ID: 8052574
I bet you'll find it's some quirk in Notepad that does it. Try this:

Alter mainClass.txt and add a blank line after the

Main-Class: KathySaver

Also make sure you put the arguments to jar in the right order.

jar cvfm kathysaver.jar mainClass.txt *.class

Good luck.

-coljac
0
 

Author Comment

by:jayirvin
ID: 8053436
when I ran it as the above. I got this error
java.io.IOEception: invalid header field
at java.util.jarAttributes.read(Attributes.java:359)
at java.util.jar.Manifest.read(Manifest.java: 162
at java.util.jar.Manifest.<init><Manifest.java:52>
at sun.tools.jar.Main.run<Main.java:124>
at sun.tools.jar.Main.main<Main.java:904>

I know not what they mean
Jay
0
 

Author Comment

by:jayirvin
ID: 8053662
I did get the manifest file to include
Main-Class: KathySaver
KathySaver.class being the main class in the jar used to exicute the screen saver. but when I try to run it from a command promt I get this error:Failed to load Main-Class manifest attribute from kathysaver.jar
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:coljac
ID: 8053956
There's probably a type somewhere. I checked and I could get a test class working fine. For example:

File Col.java

public class Col {
  public static void main(String[] args) {
     System.out.println("OK");
  }
}

File col.man
Main-Class: Col

Then I ran
javac Col.java
jar cfmv col.jar col.man Col.class
java -jar col.jar

And got
"OK"

I'd suggest checking the order of the flags to jar again, and double-checking for typos.

-Coljac
0
 

Author Comment

by:jayirvin
ID: 8054697
I tryed to recreat the above program with jcreator and it runs fine in jcreator but no from a command prompt I am not sure where this code goes:
File col.man
Main-Class: Col
I just jared it and ran it and got an error Main-Class not found
0
 

Expert Comment

by:coljac
ID: 8055214
What I meant, actually, is that the file "col.man" contained only the text "Main-Class: Col" and a newline.

If you copy the class defition above to a file called Col.java, and the line "Main-Class: Col" to a file called col.man, then the three lines

javac Col.java
jar cfmv col.jar col.man Col.class
java -jar col.jar

Ought to work fine. From there, you can substitute for your own classes and main class name, until it stops working. Then we'll have a better idea of what could be going wrong.

However, if you got the error "Main class not found", perhaps it's nearly working. Are you sure you have the right class name in your manifest? Remember, if your main class (KathySaver) is in a package, you'll need to include that as part of the classname (e.g. Main-Class: my.package.KathySaver). Case matters too.

0
 

Author Comment

by:jayirvin
ID: 8057634
Im not sure about this package term. my program is a subclass of Applets and i have packages imported.

//first four lines of code
import jpb.*;
import java.awt.*;
import java.applet.Applet;

public class KathySaver extends Applet{

does this mean its in a package? could i send you the whole jar to try. It's a pretty cool screen saver if we could just get it to run outside JCreator. I really appreciate your help, Jay -  www.silvereagledesign.net
0
 

Accepted Solution

by:
coljac earned 200 total points
ID: 8058636
No, it's not in a package. A package line is the first in the code, and looks like

package my.package;

I have two more remarks to make... Why are you trying to run an applet from the command line? Applets are designed to run in web browsers. There are ways to do it but I'm wondering if that's what you mean to do. It seems likely to me that JCreator has an applet viewer built in. Does the class KathySaver have a main() method?

If the main-class thing is still giving you problems, there's another way to run it from the jar.

java -cp kathysaver.jar KathySaver

That way you're telling it explicitly what the main class is.

If you have no luck, paste the whole KathySaver class here so I can have a look.
0
 

Author Comment

by:jayirvin
ID: 8058828
I have tryed to embed the applet into the web page and it has a grey screen. So I tryed to run it from the command line figuring if it would run there it would run on the web site. The screen saver has three classes. KathySaver.class, Ball.class and Sketchpad.class
My wife Kathy is taking a second quarter Java class at college and her instructor told her to take out the public statements in the sub classes and it would save it as one file and make an applet with one class. That didn't work. It has one file with three classes in a folder named classes. There is alot of code in these three classes. If you could send me an email adress to Jay@silvereagledesign.net I would zip them and email them to you  
0
 

Author Comment

by:jayirvin
ID: 8058841
coljac truley went out of his way to help me.
0
 

Author Comment

by:jayirvin
ID: 8058979
I ran this the way you suggest coljac and I got these error messages:
Exception in thread "main" java.lang.NoClassDefFoundError:L jpb/DrawableFrame
at Sketchpad.<init><KathySaver.java:63>
at KathySaver.main<KathySaver.java:15>

Do they tell you anything about the problem?
0
 

Expert Comment

by:coljac
ID: 8059157
I can see that you're using several external libraries in your code... for example the jpb classes (as indicated by "import jpb.*;" in your applet. So you need to make these available at runtime. If you have a jpb.jar you run with

java -cp kathysaver.jar;jpb.jar KathySaver

Substitute jpb.jar for the full path to the jar if you know where it is. If not, you'll have to figure it out with your IDE.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question