Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

weird error in a jar file when i trie to copy and create a file

 
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone
this question is also in the I/O and stream and im sorry i do not really know hos to delet post and i moved it here because i dont think it belong to this section anymore if you know how to delet post hope you can guide me
i have a class GUI that edit multiple png and show it in the window if i execute this code from eclipse it work perfectly but when i want to export to a jar file and launch it (in windows) some weird error message are poping and i do not really understand it



here is my class that edit and read my png



i hope you can explain why is it working in eclipse ide but not in a jar file
 
Marshal
Posts: 72476
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check the location of the XXX.png file. Eclipse uses paths relative to the root of the project (I think) but if you run the program from the command line, paths may be relative to the current directory.
 
Cyan Rick
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont think its this because it work perfectly in eclipse and here my architecture

->morpion
|
|->JRE system Lib
|->src
 |
 |->morpion
   |
   |->all my class file
   |-> all my png file

so my path is actually src//morpion//
and im runing my code from eclipse but it show the error code in my post only when i use the jar file
 
Master Rancher
Posts: 3831
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest adding a line to your method:

I think you will find that the absolute path to the files you're copying is not what you think it is.  Most likely, you are starting from a different home directory.  The simplest way to fix this would be to put an absolute path in your "path" constant, meaning one that begins with / or (for Windows) a drive, like "C:".  Something like this:
 
Cyan Rick
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi mike it seem that you are ritght about my absolute path but if i make a full path then my jar file will not work because it might be in another device or folder no ?

Attempting to copy from
C:\Users\user\eclipse-workspace\morpion\src\morpion\tictactoe_sav.png
to
C:\Users\user\eclipse-workspace\morpion\src\morpion\tictactoe.png

what i want with the information you give me is the absolute path to my png in my jar file so even if i share my jar its still work
 
Master Rancher
Posts: 4256
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

path to my png in my jar file


When files are placed in jar files they become resources.  You don't normally use File objects to access resources.
Look at the Class class's getResource and getResourceAsStream methods.
 
Saloon Keeper
Posts: 12825
279
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Norm is correct. Resources that are part of the project sources are packaged into the JAR and need to accessed through Class.getResourceAsStream(). The path to use is relative to the path of the class that you called the method on. The easiest thing to do is put the resource in the same package as the source file you will be using it in. Otherwise, use an absolute path. Absolute paths are relative to the root package (the source folder):
 
Cyan Rick
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks you Stephan and Norm for your reply and explain that was a hudge help i have edited my code according to your suggestion i can load at least my first png but he show me error telling me that NoSuchFileException because he cant find the file i guess and i dont really understand why when i launch my jar file he load the first png (tictactoe_sav) but cant load the next and i cant make a getRessourcesAsstream to my file b because i want to delet it (replace it)after and cant do that if i use getressources





 
Stephan van Hulst
Saloon Keeper
Posts: 12825
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Norm already pointed out, you don't perform File operations on resources. They are not files, resources are compressed into your JAR. Resources are only there to be read by your application.

What you're doing doesn't make sense. Why would you want to copy tictactoe_sav.png to tictactoe.png? Just keep the combined image in memory, don't save it to disk. Even if you insist on saving it to disk, don't save it to your project folder. When your application is deployed on a client system, the installation folder will not reflect your project directory layout.

Why are you combining the images into one at all? If you're using a GUI framework such as Swing, just paint the images to a canvas on the fly, instead of combining them into one image first.
 
Norm Radder
Master Rancher
Posts: 4256
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.nio.file.NoSuchFileException: src\morpion


Does that target path exist?
 
Danger, 10,000 volts, very electic .... tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic