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 .
Related
I've create simple java project with single class - Main with main method printing Hello.
package com.foo;
public class Main {
public static void main(String[] args) {
System.out.println("Hello!");
}
}
Code was compiled to bin directory. I'm trying to create jar using command
jar -cfe project.jar com.foo.Main -C bin\
with no results, always returning Error parsing file arguments error.
I also tried many different variations, like
jar --create --file project.jar --main-class com.foo.Main -C bin
but none of it worked. I'm using Java 16
Try running this. It should create the 'project.jar'
jar --create --file project.jar --main-class com.foo.Main -C bin .
-C flag Temporarily changes directories (cd dir) during execution of the jar command while processing the following inputfiles argument.
This command changes to bin directory and adds to project.jar all files within the bin directory (without creating a bin directory in the jar file).
For more information check the -C part in the OPTIONS section :
https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html#options
You need both a "=" after main-class and a "." at the end to selct al lthe files
jar --create --file project.jar --main-class=com.foo.Main -C bin .
or
jar cfe project.jar com.foo.Main -C bin .
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)
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.
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.
I have next package structure
webService.ear -- dependency.jar -- some.class
Can I remove some.class from .ear using cmd script and bash script?
Solution:
I wrote cmd script for this:
call unzip target\webService.ear -d tmp
call zip -d target\tmp\dependency.jar \com\mypackage1\MyClass1.class
call zip -d target\tmp\dependency.jar \com\mypackage2\MyClass2.class
call jar cvfM target\webService.ear -C tmp .
May be, this will be helpful for someone
There is no option to the jar command to remove entries.
However, the jar format is processable with zip tools, so you should be able to use a command-line zip (GNU zip, for instance) to remove members.