Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem using Jar file

Reply
Thread Tools

Problem using Jar file

 
 
smita bhopale via JavaKB.com
Guest
Posts: n/a
 
      05-31-2005
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.

--
Message posted via http://www.javakb.com
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-01-2005
On Tue, 31 May 2005 07:16:25 GMT, smita bhopale via JavaKB.com wrote:

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

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
 
smita bhopale via JavaKB.com
Guest
Posts: n/a
 
      06-03-2005
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-
IOExceptionage could not be loaded :Invalid URL

--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200506/1
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-03-2005
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.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
smita bhopale via JavaKB.com
Guest
Posts: n/a
 
      06-06-2005


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.

--
Message posted via http://www.javakb.com
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-06-2005
On Mon, 06 Jun 2005 06:05:30 GMT, smita bhopale via JavaKB.com wrote:

> 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)?

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
smita b via JavaKB.com
Guest
Posts: n/a
 
      06-06-2005
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.

--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200506/1
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-06-2005
On Mon, 06 Jun 2005 14:02:39 GMT, smita b via JavaKB.com wrote:

> 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.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
smita bhopale via JavaKB.com
Guest
Posts: n/a
 
      06-08-2005
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.

--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200506/1
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-08-2005
On Wed, 08 Jun 2005 05:52:42 GMT, smita bhopale via JavaKB.com wrote:

> Thank you for the help .


You're welcome.

> ..Now it is working fine.


That is excellent.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to print out the currently used JAR file path to verify itis using right JAR? markspace Java 2 10-07-2011 06:17 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57