Problem using Jar file

  • Thread starter smita bhopale via JavaKB.com
  • Start date
S

smita bhopale via JavaKB.com

I have one prblem related with using jar files.
I have created one jar file of my application.In my application I am
loading web browser & showing html pages which resides in another directory
other than where my application.class file resides.

while creating jar file i have used following command
jar cvmf Manifest.txt name.jar directory[which includes html pages]
In jar file it is not creating resource folder.

In source file I have used
editor.setPage(getClass().getResource("/directoryname/filename.htm"));
//works

Jar file includes directory ,but If I run jar file it is throwing
IOException at run-time that
Page could not be loaded :Invalid URL

What should I used so that the code will work fine.
 
A

Andrew Thompson

In source file I have used
editor.setPage(getClass().getResource("/directoryname/filename.htm"));
//works

Jar file includes directory ,but If I run jar file it is throwing
IOException at run-time that
Page could not be loaded :Invalid URL

What should I used so that the code will work fine.

Improve your debugging techniques for starters.

What is the exact string returned by ..
getClass().getResource("/directoryname/filename.htm")
?

And more importantly, why did you feed it directly to editor.setPage()
when things are not working? First principle of debugging is to
prove exactly what *is* happening. The first part of that is to
discover the exact URL that call is returning - use System.out.println()
to dump it to standard out.

And as an aside, there is another group better able to help
people starting in Java, more details here..
<http://www.physci.org/codes/javafaq.jsp#cljh>
 
S

smita bhopale via JavaKB.com

If I print using System.out.println(getClass().getResource
("/directoryname/filename.htm"));

It is printing the exact url that I want.

If I run the code using java classname then it is working fine.But for the
same class if I create a jar file.After runnint that jar file actully I got
an error that-
IOException:page could not be loaded :Invalid URL
 
A

Andrew Thompson

On Fri, 03 Jun 2005 09:19:26 GMT, smita bhopale via JavaKB.com wrote:

Please include a little of the words you are replying to smita,
so that someone who has missed the earlier posts might understand
what is happening.
If I print using System.out.println(getClass().getResource
("/directoryname/filename.htm"));

It is printing the exact url that I want.

(shakes head sadly) I did not ask if 'the' URL was 'what you want',
I asked ..

"What is the exact string returned by ..
getClass().getResource("/directoryname/filename.htm")
?"

The reason I ask is that the string should be different for the
jarred and unjarred versions.

So, to repeat, (and expand), can you give us the *exact* printout,
letter for letter, that prints for the two versions.
 
S

smita bhopale via JavaKB.com

Hello Andrew Thompson ,

Using-
System.out.println(getClass().getResource("/sc/default1.htm"))---printing:
following string-
file:/c:/try/sc/default1.htm

It is working with java classname command.
But if I create a jar file for the same class then it is not working.
How can I solve this problem,please write me.
 
A

Andrew Thompson

Using-
System.out.println(getClass().getResource("/sc/default1.htm"))---printing:
following string-
file:/c:/try/sc/default1.htm

This is wrong.

The call to get resource is not finding the version of the 'default1.htm'
inside any jar file, but as a separate file on the local filesystem.
You might try moving the jar to a different location before running it.

BTW - is that string really 'file:/c:/..', or 'file:/C:/..' (drive letter
as capital/upper case letter)?
 
S

smita b via JavaKB.com

Yes.You are right.
It is actually printing:

file:/C:/try/sc/default1.htm

If I move the jar to other location it is not working.
But what should I use so that on running jar file it work fine.
Which statement I should include?
Please write me.
 
A

Andrew Thompson

Yes.You are right.

(By saying enough things) I often am.
It is actually printing:

file:/C:/try/sc/default1.htm

Aha! I want to pause for a moment, now that I have *finally*
managed to get you to copy/paste exactly what you are seeing,
to savour the moment. ..OK, done.
If I move the jar to other location it is not working.

Now.. I want to know *exactly* what the same string is for the
jar, this is more tricky, since System.out.println() can be dumped
to a 'black hole' for some jar files. You might need to resort
to showing it in a JTextArea (so you can copy it) in a JOptionPane.

By the way. Did you say this file was included *inside* the
jar file? I recall you said you added the directory to the
jar, but just check that using the jar 'list' option. E.G.

jar t jarname.jar
But what should I use so that on running jar file it work fine.
Which statement I should include?
Please write me.

Please *stop* saying that! I do not 'write you' but
'write the group'. And note that anyone else is also
free to 'write the group', not just me and you.

...and perhaps I should explain that you are accessing a
usenet newsgroup through a web page at JavaKB. I am not
(*we* are not) a part of the JavaKB site, but just a person
who reads this newsgroup.

Hope that helps.
 
S

smita bhopale via JavaKB.com

Thank you for the help . Now it is working fine.

After debugging I got exact mistake.
One filename from my directory was different than what I was accessing.
I useally testing that page only.

Thx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top