0

I am trying to create a jar file for the .java program

followed the steps as

Step 1. Create a 'mywork' folder Step 2: Put the XYZ.java and the gson.jar file under the mywork folder Step 3. Use javac -cp .:gson.jar XYZ.class Step 4. Create Jar File -> jar cf XYZ.jar XYZ.class Step 5. Create a Manifest.txt and modify it to include MainClass:XYZ Step 6. Modify Manifest.txt to include classpath for gson.jar Step 7. Then run the command-> jar cfm XYZ.jar Manifest.txt XYZ.class argument1 argument2 

when I am doing step 7 I am getting

"java.io.IOException: invalid header field" error 

Where am I going wrong, please help me to solve the problem.

My Manifest.txt is like

Manifest-Version: 1.0 Class-Path:gson.jar Created-By: 1.7.0_06 (Oracle Corporation) Main-Class: XYZ 

main method:

public static void main(String[] args) throws Exception { // Enter the values for the arguments String dirstr = args[0]; String logfiledirstr = args[1]; XYZ data = new XYZ(); data.method1(dirstr,logfiledirstr); } 
5
  • What are your argument1 and argument2? Commented Apr 6, 2014 at 16:49
  • @Mureinik inputs are CSV files. Also Edited to include the main class. Commented Apr 6, 2014 at 16:53
  • a stacktrace might help in the disgnostic (or at least XYZ code) Commented Apr 6, 2014 at 16:55
  • 3
    only a shot in the dark but maybe 'Class-Path:gson.jar' is missing a space between the : and the gson.jar Commented Apr 6, 2014 at 17:15
  • @WilliamReed No space as well. Thanks for pointing it out. Commented Apr 6, 2014 at 17:21

2 Answers 2

1

You need to prefix value with space after the semicolon

change

Class-Path:gson.jar 

to

Class-Path: gson.jar 

viz http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Name-Value_pairs_and_Sections

value:SPACE *otherchar newline *continuation

Sign up to request clarification or add additional context in comments.

Comments

1

There has to be a "New Line" at the end of your manifest file. Give a New line and then check.

Your file must be like this:

Manifest-Version: 1.0 Class-Path: gson.jar Created-By: 1.7.0_06 (Oracle Corporation) Main-Class: XYZ (Press Enter) 

5 Comments

Thanks for the suggestion, but I am not sure what does that mean?
@user3188390 it means open your manifest file, hit enter (to create a new line), then save it.
@Subodh : No it did not work. Thanks for the suggestion.
I am just guessing now. Give a space between "Class-Path:" and "gson.jar" and try.
That's the format used by the Manifest file...Glad that it worked..:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.