• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access file system from enterprise bean

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • 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
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better put the file as a part of deployment jar and read from there.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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.
 
Harm de Laat
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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).
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
And in my specific case? Because i'm violating the spec, can I break something?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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).
 
norman richards
Author
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • 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)
 
A Wolfe
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Delegating the use of java.io.* to a helper class is no different from using it directly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic