Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

[solved] Weird error when launching .jar vs .class

 
Greenhorn
Posts: 22
Mac Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.

I am still trying to access a directory out of a jar.
I found a way around, this to use :



What's funny and depressing at the same time, is that it does not behave the same at all when I launch the app through the IDE (which launches the .class) and the jar.

The last line of the code i have given should print the path to the executable.
- When i launch it with the IDE (.class), i get this:

which is fine and working

- When i launch the .jar i have got something different:

Appart from the change of directory (which is fine), there is an extra "file:" string that appeared out of nowhere and causes following code to crash.

Why does the .jar and .class behave differently for this issue? And how to find a workaround?

Thanks a lot
jy
[ August 25, 2007: Message edited by: Jean-Yves Tinevez ]
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure about the "why", but isn't the workaround as simple as checking if the path starts with "file:" and removing the unneeded 5 characters if necessary.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this might be a bit advanced for the beginners forum, so I'm promoting this topic to the intermediate forum.
 
Jean-Yves Tinevez
Greenhorn
Posts: 22
Mac Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.

I think i have found the why:

(WARNING: evcerything done on MacOSX10.4)

When you do this:

the executableDir will be differently formed if called from a .class or from a .jar. You can see it with the toString() method. Suppose you convert this to a string.

- When called from a .class, it will be formed like this:

which can be correctly accessed

- When called from a .jar, it is like that:

Now if you convert it back to a file, it won't be processed correctly: the 'jar:' prefix will be removed, but not the 'file:' one (apparently it can remove only one prefix).
Which explains the weird log posted up there.

The solution for me was simply to add a line of code manipulating the String to remove the 1st characters up to the 1st ':'

But that's still strange no? What do you think of it?
reply
    Bookmark Topic Watch Topic
  • New Topic