1

I am trying to create a jar file with many classes. Using the following command

C:\Users\use\Desktop\SDE_7_SSH\eclipse\new\charge\src\jar> jar cf charge.jar *.class 

But it is throwing an error 'jar' is not recognized as an internal or external command, operable program or batch file.

In my jar folder (C:\Users\use\Desktop\SDE_7_SSH\eclipse\new\charge\src\jar), i am having two other folders named "f1", "f2", which inturn having classes.

1
  • When i try to use the following command, i am getting the error respectively C:\Users\use\Desktop\SDE_7_SSH\eclipse\new\charge\src\jar>java -jar cf charge.jar *.class Error: Unable to access jarfile cf it is Commented Aug 24, 2012 at 5:51

3 Answers 3

1

You need to run the jar command from bin directory. For example on linux system, I would either go to my directory

cd /usr/local/java/jdk1.6.0_01/bin/

and then run

jar cf charge.jar *.class

or else run it with the full path of java binary

/usr/local/java/jdk1.6.0_01/bin/jar cf charge.jar *.class

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

Comments

0

Use 'java -jar' Not just 'jar'

2 Comments

When i try to use the following command, i am getting the error respectively C:\Users\use\Desktop\SDE_7_SSH\eclipse\new\charge\src\jar>java -jar cf charge.jar *.class Error: Unable to access jarfile cf it is
java -jar is used to execute a JAR archive not to create one.
0

Use the complete path to the jar program, which is in Java's bin directory. Like

jdk_with_version\bin\jar cvf *.class

5 Comments

Since i am new to java, can you give me detailed example
Follo this link (www.cis.upenn.edu/~matuszek/cit594-2002/Pages/jar-files.html) this could help you to solve
i am able to create jar file. But after adding the jar file to my project it is showing class not found errors. I checked my jar files by using the command D:\charge>D:\rrr\bkk\"core java"\software\Java\Java_1.6.0_ 04_win\jdk1.6.0_04\bin\jar xvf charge.jar. It is having the .java files, but i am getting class not found error in my project.
Extract your jar and see whether you could find the classes which your looking for?
Make sure whether you have added the jar file to the classpath in run configurations and execute

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.