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
    – BKK
    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

0

Use 'java -jar' Not just 'jar'

2
  • 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
    – BKK
    Aug 24, 2012 at 5:55
  • java -jar is used to execute a JAR archive not to create one.
    – dragn
    Aug 24, 2012 at 7:06
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
  • Since i am new to java, can you give me detailed example
    – BKK
    Aug 24, 2012 at 5:55
  • Follo this link (www.cis.upenn.edu/~matuszek/cit594-2002/Pages/jar-files.html) this could help you to solve
    – thar45
    Aug 24, 2012 at 6:08
  • 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.
    – BKK
    Aug 24, 2012 at 7:05
  • Extract your jar and see whether you could find the classes which your looking for?
    – thar45
    Aug 24, 2012 at 7:10
  • Make sure whether you have added the jar file to the classpath in run configurations and execute
    – thar45
    Aug 24, 2012 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.