• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Creating a File object from a java class, when both are deployed in the same package!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a requirement to embed an image in an excel file dynamically from a Java class. The Java class is a part of the web module of an EAR file which is getting deployed in WAS 5.0.

To embed the image in the excel file at the runtime, I need to create a file object for the same. I can do that easily if I save the image somewhere on 'C' drive and provide its exact path to the File class constructor. But I do not want to do that.

Instead I want to bundle the image file in the EAR. I tried this by saving the image file under the same package where the above java class (from where I want to create file object) resides.
But the problem is that, the class is not able to recognize/locate the file and giving 'FileNotFoundException', when I try to embed it in the excel file.

Is there any way we can access the image file from the java class, while bundling it in the EAR file?

Thanks,
Shailesh.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this post give you any ideas?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shailesh Deshpande:

Is there any way we can access the image file from the java class, while bundling it in the EAR file?





in some circumstances, this will give you the actual path to the image. i do not know anything about EJBs. however, in JSP, my experience has been that the file has to be somewhere where the "real path" makes sense -- you have to have access to in within the web server context. (e.g., you probably won't be able to access the file if it's on the root directory of the server.) you may be able to determine the real path to the file without actually being able to access it.

thanks.

mp
 
Do you pee on your compost? Does this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic