Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Problem using Jar file

Thread view: 
smita bhopale - 31 May 2005 08:16 GMT
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.
Andrew Thompson - 01 Jun 2005 11:53 GMT
> In source file I have used
> editor.setPage(getClass().getResource("/directoryname/filename.htm"));
[quoted text clipped - 5 lines]
>
> 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>

Signature

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

smita bhopale - 03 Jun 2005 10:19 GMT
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
Andrew Thompson - 03 Jun 2005 11:04 GMT
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.

Signature

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

smita bhopale - 06 Jun 2005 07:05 GMT
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.
Andrew Thompson - 06 Jun 2005 07:48 GMT
> 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)?

Signature

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

smita b - 06 Jun 2005 15:02 GMT
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.
Andrew Thompson - 06 Jun 2005 16:29 GMT
> 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.

Signature

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

smita bhopale - 08 Jun 2005 06:52 GMT
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.
Andrew Thompson - 08 Jun 2005 07:52 GMT
> Thank you for the help .

You're welcome.

> ..Now it is working fine.

That is excellent.  :-)

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.