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

Access file system from enterprise bean

 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
Because an enterprise bean cannot must not use java.io package to access file and directories in the file system.
How does an enterprise bean access files or directories in the file system?
thanks
daniel
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better put the file as a part of deployment jar and read from there.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what you are trying to do. I am all in favor of breaking the no java.io.* rule in some cases. For example, I see no problem in accessing the file system to get a complex configuration file and in some cases it can't be easily avoided (ie. third-party libraries that use config files). However, I would definitely recommend staying away from any read-write file IO.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should you not use java.io.* in EJB's?
For instance, I have a MessageDrivenBean which does some image processing.
In my JMS message to the bean I include the absolute path to the image file.
Then I do the processing, and save the image.
Is there anything wrong with that? (I'm asking because I have to use the java.io.File class).
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why should you not use java.io.* in EJB's?


Because the EJB specification tells you not to... In practice, however, you can break this rule and many times you simply have to.
 
Harm de Laat
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And in my specific case? Because i'm violating the spec, can I break something?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can break the spec but in your case, I would implement the file/image processing stuff in such a way that a possible rollback of a transaction would not mess things up (for example, use a temp file that won't affect your program even if it is left hanging around for some reason).
 
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One nice trick is to bind part of the filesystem in via JNDI and access files on the filesystem that way. With JBoss this is pretty straightforward. It might be harder to do in other app
servers. (and as such really couldn't be considered a portable technique)
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you add a helper class that will do the file processing and give the data back to EJB that you need to use in EJB?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Delegating the use of java.io.* to a helper class is no different from using it directly.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic