• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1039
  • Last Modified:

Executing a unix shell script from an EJB

Hello,

I'm just starting with J2EE, so I hope you will bear with a very ignorant question. I have a legacy website which I would like to reimplement using some sort of MVC pattern.  The site runs ksh scripts, and reads the resulting files, and the new site must do the same.

Can an EJB make calls out to the shell?  How do I  go about this? (I.e. is there anything special that I should know for it to work within J2EE?)

Many thanks!

Roger Pearse
0
roger_pearse
Asked:
roger_pearse
  • 2
1 Solution
 
anumalasCommented:
Hi Roger

We can not call your shell scripts from your EJB. If it is manditory for your requirement you can Use struts frame work for your site. This Frame work will follow MVC 2 Design pattern and from Action class you can call Shell script like bellow

Process someAppProcess; //Handle to the process
try
{
someAppProcess = Runtime.getRuntime().exec("/usr/business/scripts/urscript.sh");
}
catch(java.io.IOException e)
{
//Handle an IOException here.
return;
}


after getting script results put those results as per your wish. Some best practices are hold results in collection object, prepare DTO and pass it to the middle tier, means pass that DTO to Any session bean (EJB) from that middle tier you can communicate with the database.

Hope you have clear understading about MVC. If you are not willing to use Struts frame work you can write that code in ur Servlet also.

Hope this will help you and all the best for your site improvements :)
0
 
roger_pearseAuthor Commented:
Many thanks for this.  What is a DTO?  (I think that I understand the MVC pattern, so your comment is helpful).
0
 
ramazanyichCommented:
if you are using JBOSS then it comes with BSH deployer. Check http://wiki.jboss.org/wiki/Wiki.jsp?page=BSHDeployer
and check beanshell documentation: http://www.beanshell.org/docs.html
0
 
anumalasCommented:
Hi Roger

DTO means Data Transfer Object. This is used to transfer data from one tier to another tier. i.e., Presentation Tier to Business Tier or Middle tier. Instead of sending each and every varible or filed value to server we will prepare one DTO and send it to Business tier. That will reduce network usage and improves performance of your application
0

Featured Post

The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now