?
Solved

merg a text file into manifest

Posted on 2003-03-02
12
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 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