Hectic
Hectic

Reputation: 61

Error creating JAR file using Command Prompt

I've come across a problem, when trying to package my Java files. I have three Java files: OneMessage.Java, TwoMessage.Java, and AllMessages.Java. I'm on Windows, and so I used cmd to compile these files:

javac OneMessage.Java
javac TwoMessage.Java
javac AllMessages.Java

I then created a Manifest file - using Notepad - with the following and saved it as Manifest.mf:

Manifest-Version: 1.0 
Main-Class: AllMessages

(There's a single line after "Main-Class: AllMessages".)

However, when I tried to create my executable JAR file, a problem occurs, stating that the system cannot file the file specified (the file is in the source folder btw). And this is what I input to create my JAR file:

cvmf AllMessages.jar Manifest.mf *.class

However, I get the following: "java.io.FileNotFoundException: Manifest.mf (The system cannot find the file specified".

Help is appreciated as ever.

Upvotes: 2

Views: 2318

Answers (2)

Daileyo
Daileyo

Reputation: 720

Not a Java guru, but I think the problem may be that your JAR and Manifest file are ordered wrong. Per the documentation on the Java options, I think that m and f need to correspond to the ordering of your Manifest and JAR files, respectively. Sounds like it should be:

jar cfmv AllMessages.jar Manifest.mf *.class

Upvotes: 2

Hectic
Hectic

Reputation: 61

I got this to work. I had two sort out two things. My Manifest.mf file was saved as a Text Document, so I went back and changed that to All Files.

I then went onto Oracle and found out that the basic command for creating a JAR file on Command Prompt is:

jar cf jar-file input-file(s)

So I changed my code from

cvmf AllMessages.jar Manifest.mf *.class

to

cf AllMessages.jar Manifest.mf *.class

And I successfully created a JAR file. Note that even if you save your Manifest.mf file as a Text Document, it will still create a JAR file for you.

Link to creating a JAR file: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

Upvotes: 0

Related Questions