I'm trying to make a 'jar file' and run it by first making manifest file.
as I enter jar command in command prompt and using all explanation, this is what I think is sensible:
>md build\classes ----first I made a directory for my class files--
>javac -d build\classes src\*.java ----then compile java files from src folder to classes folder----
>javadoc src\*.java -d doc ----make documentation----
>jar -cfm my.jar m.txt -C build\classes ----I want to make a my.jar file and put the manifest contents from .class in build \classes to m.txt but I don't know what's wrong that I can't make a manifest file as m----
java -jar my.jar
I mentioned above the problem in making manifest file so that I can run .jar file.
what's wrong with my code for making the manifest file?
this is what it print when I run the command for making manifest file:
Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Simply add a . at the end of your jar.exe command, or whatever you wish to include from the build\classes directory. The -C command allows you to change directory, but you then need to specify what to include from that directory thereafter.
So...
jar -cfm my.jar m.txt -C build\classes .
I'm assuming that your manifest file is already created. If not, then you can echo via the command line and output it to a file. For example...
echo Main-Class: path.to.YourClass > MANIFEST.MF (or m.txt)
Related
C:\Users\Desktop\ExploreWS\Explore>jar cvf Test.jar bin\com\test\Te
st1.class
'jar' is not recognized as an internal or external command,
operable program or batch file.
Please help to resolve this issue. Basically I'm trying to create a jar file without main class using window command prompt.
Receiving proper help message when I was trying to execute only jar command in command prompt
C:\Users\Desktop>jar
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-n perform Pack200 normalization after creating a new archive
-e specify application entry point for stand-alone application
bundled into an executable jar file
-0 store only; use no ZIP compression
-P preserve leading '/' (absolute path) and ".." (parent directory) compone
nts from file names
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.
Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
My requirement is that I want to create a jar file using project folder via command prompt but I don't have any Main class in my project. It's a Junit classes.
I've start to read about jars, But I cannot understard how jar -C works.
I've tried the following command
jar cfv Some.jar -C innertest\ForDelete.class .
when I am in E:\eclipse_workspace\Test\bin\test>.
So I expect to have PartJar.jar and files the files in it which are not in test directory. But after executing the command the result is added manifest and only manifest file is created.
So if I try jar cfv Some.jar -C innertest . it will work, but what if I want to add only 3 files in this directory not the whole directory.
Thanks in advance.
I'm not sure whether there is a solution which does not involve multiple use of -C:
jar cfv my.jar -C myDir file1 -C myDir file2
A possible workaround, if applicable to your case, could be to put only the files you need inside a new directory and use:
jar cfv my.jar -C newDir .
I have a set of documents(java, class, html) that I put into a .jar file named calc.jar with:
jar cmf MANIFEST.MF calc.jar calc.java calc.class calc.html
It creates an "executable jar" file in my folder, but it does nothing when I open it. Then I run the file in the cmd with the following:
jar -jar calc.jar
After that, it reads:
Illegal option: j
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-n perform Pack200 normalization after creating a new archive
-e specify application entry point for stand-alone application
bundled into an executable jar file
-0 store only; use no ZIP compression
-P preserve leading '/' (absolute path) and ".." (parent directory) compone
nts from file names
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.
Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
What's going on?!?
EDIT: My manifest file reads:
Manifest-version: 1.0
Main-Class: calc
Using java -jar calc.jar brings this up:
Error: Main method not found in class calc, please define the main method
However, my .java file contains the main method.
The command line syntax is off. You are attempting to execute the .jar file with the jar command, which is intended to package the files only.
Try something like this:
java -jar calc.jar calc
The java command with -jar delimeter indicates that you want to execute a jar file.
The output clearly says
-j
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
-j not supported, As NESPowerGlove rightly pointed out.
Basically you are using the jar command in wrong way. Kindly read the man page or usage carefully and try again.
Here's the code
SET PATH="C:\Program Files\Java\jdk1.7.0_40\bin"
dir *.java /b /s >> ./sources_list.txt
javac -cp ".;lib/*" #sources_list.txt -d compiled
dir compiled\*.class /b /s >> .\classes_list.txt
jar cfm app.jar MANIFEST.MF #classes_list.txt
del sources_list.txt
del classes_list.txt
PAUSE
so this is for compiling my java code (1st 3 lines) which works, then to copy the compiled classes into my jar using jar
now my problem is on line 4, finding the compiled classes and printing the path to the classes_list.txt, that works however it returns the full C:\somethin\compiled\something.class
i need it to return only the
compiled\subfolders\something.class
how can i edit that to return the path i need?
jar command can take path to classes and create directory. You need to pass only the directory not all classes.
jar cfm app.jar MANIFEST.MF compiled
should work.
I created a wordcount example in MapReduce and trying to make the jar file using following command:
hduseros#MT2012018:/usr/local/hadoop$ jar -cvf playground/wordcount.jar -C playground/classes
But Its not at all running and giving me following result:
hduseros#MT2012018:/usr/local/hadoop$ jar -cvf playground/wordcount.jar -C playground/classes
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-e specify application entry point for stand-alone application
bundled into an executable jar file
-0 store only; use no ZIP compression
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.
Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
Please correct where I am wrong. I have set the class path. I can run the examples already present but not able to make jar file.
That is probably because you haven't given it the location where it needs to pick the files from. Try this:
jar -cvf playground/wordcount.jar -C playground/classes .
And include the last dot (.)
Try eliminating the dash: jar cvf, not jar -cvf
Try to perform the following command:
jar cvf playground/wordcount.jar playground/classes/*.class
See also: Building a JAR File of Interface Classes
-C option just changes your directory to the argument you have given afterwards. You still should add the files/directories to be added to the jar file after you have switched to that directory.
Please check the documentation for jar command.