1,105,534 Community Members

'Unable to access jarfile'

joshSCH
Industrious Poster
4,845 posts since Jul 2005
Reputation Points: 1,062 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

When I try to execute my jar file through the command prompt by typing:
java -jar myJar.jar
It returns an error message saying that it can not access the jar file. Why is this? myJar.jar is the exact name of my jar file.

Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

Where is your jarfile and where are you trying to do that?
And what's your classpath?

joshSCH
Industrious Poster
4,845 posts since Jul 2005
Reputation Points: 1,062 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

my jar file is MyJar.jar located at C:\Documents and Settings\Josh\My Documents\JAVA Programs.
My Class path is payroll, The jarfile and manifest files are all correct I believe.
I am trying to execute 'payroll' through the command prompt.

Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

you'd have to be in that very directory then. And add '.' to your classpath and path.

joshSCH
Industrious Poster
4,845 posts since Jul 2005
Reputation Points: 1,062 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

how would you get into that directory?

Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,

Do this list what is in your manifest file here. Also list exactly what you are typing on the command line with all the full path and class path so we can see what's wrong

Richard West

joshSCH
Industrious Poster
4,845 posts since Jul 2005
Reputation Points: 1,062 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

I am sure that my jar and manifest files are correct:
Manifest-Version: 1.0
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: Payroll


I was typing in the command prompt: java -jar myJar.jar
it returns 'unable to access jar file.

my jar file is myJar.jar located at C:\Documents and Settings\Josh\My Documents\JAVA Programs.
My Class path is payroll

Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,

Do this

java -jar -cp .;C:\Documents and Settings\Josh\My Documents\JAVA Programs myjar.jar

I haven't run java programs from the command line for quite some time but i think this is it. Someone correct me if i am wrong

The manifest file looks correct.

Let me know if it works

Richard West

joshSCH
Industrious Poster
4,845 posts since Jul 2005
Reputation Points: 1,062 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

hmm.. when I type that in it says 'Unable to access jarfile and'
Maybe its because the starting prompt says: C:\Documents and Settings\Josh> ?

Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,

hmm.. when I type that in it says 'Unable to access jarfile and'
Maybe its because the starting prompt says: C:\Documents and Settings\Josh> ?

The starting prompt needs to be the location of java.exe

Richard West

Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

Hi everyone,

The starting prompt needs to be the location of java.exe

Richard West

No it doesn't. As long as java.exe is on the path you're fine.
And that's not his problem anyway. His problem is a path problem where he can't find a jar he tries to launch.
So all he needs to do is call java with the correct location for the jar, which he doesn't seem capable of doing for some reason.

A beginner's course in using a command prompt might be in order :mrgreen:

Question Answered as of 8 Years Ago by freesoft_2000 and jwenting
Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,

You have to forgive me for the wrong code as i have not run jar files from command lines since 1998 but this is what you need to put exactly on the command line.

Say your jar file is at "C:\Josh.jar"
Say your java.exe file is at "C:\java\bin\java.exe"

Type this exactly

C:/java/bin/java -jar C:\josh.jar

remember that the -jar has a space on either of its side and for the java.exe don't include the .exe

I usually try to run my jar files programatically using the Runtime class as with that i can get both the error and output stream of the runtime.

Let me me know how it works out

I hope this helps you

Thank You

Yours Sincerely

Richard West

Member Avatar
joankim
Junior Poster in Training
59 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey. I know this thread is EXTREMELY outdated, but it is still almost at top at google, and I did not find this solution anywhere else online. I just changed the starting prompt location to the folder in which the jar file is located. For example, if your jar file location and name is: C:\Users\Tod\file.jar, you can do two commands:
cd C:\Users\Tod

java -jar file.jar

This worked for me, hope it helps!

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article