user3188390
user3188390

Reputation: 613

how to create jar file?

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);
}

Upvotes: 0

Views: 171

Answers (2)

SubodhD
SubodhD

Reputation: 308

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)

Upvotes: 1

Hurda
Hurda

Reputation: 4715

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

Upvotes: 1

Related Questions