How to execute a java application once the server starts

I have created a java application which executes correctly. I want this application to execute everytime I start my server. I have modified my web.xml as shown below
<servlet>
<servlet-name>SendEmail</servlet-name>
<servlet-class>
com.allcorp.alliance.tdocs.servlets.SendEmail</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
<load-on-startup>1</load-on-startup>
</init-param>
</servlet>
I have extended the class with HttpServlet. When I start the server, I get the message saying the class is being initializing but it does not execute. I want the application to execute. Any idea what I need to do.

BalusC wrote:
Implement ServletContextListener and run the appplication on creation of the ServletContext.Well i understand implementation of ServletContextListener and by overiding contextInitialized(ServletContextEvent se) accordingly can solve the problem.
but you need to consider two cases here first
1).ServletContextListener is not supported by all container especially the minor onces which does not support Servlet 2.3 specification.
2).OP does not have any idea of how to use a Servlet first if you can see he had written his intialization code in the main method.Now how can you expect him to create a listener..... :)
I hope there are no hard issues on what i said this time.
*@OP*
My friend the bad news is that you need to spend bit of time learning about servlets.U'd not be writing intialization code inside a main rather you'd be doing it inside public void init(ServletConfig config) method.
by making <load-on-startup><!--value</load-on-startup> in web.xml enables Servlet container to call init method at the time of deployment of the web application else where it'd call the init method whenever servlet encounters first request from a client.
package com.allcorp.alliance.tdocs.servlets;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.activation.*;
* @author ssa3z
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public class SendEmail extends HttpServlet{
public void init(ServletConfig config) {
    // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
    String to = "[email protected]";
    String from = "[email protected]";
    // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
    String host = "smtp.allstate.com";
    // Create properties, get Session
    Properties props = new Properties();
   // If using static Transport.send(),
  // need to specify which host to send it to
  props.put("mail.smtp.host", host);
  // To see what is going on behind the scene
  props.put("mail.debug", "true");
  Session session = Session.getInstance(props);
  try {
     // Instantiatee a message
     Message msg = new MimeMessage(session);
     //Set message attributes
     msg.setFrom(new InternetAddress(from));
     InternetAddress[] address = {new InternetAddress(to)};
     msg.setRecipients(Message.RecipientType.TO, address);
     msg.setSubject("Test E-Mail through Java");
     msg.setSentDate(new Date());
     // Set message content
     msg.setText("This is a test of sending a " +"plain text e-mail through Java.\n" +"Here is line 2.");
     //Send the message
     Transport.send(msg);
  }catch (MessagingException mex) {
    mex.printStackTrace();
} Hope this might help :)
REGARDS,
RaHuL

Similar Messages

  • How to invoke a java application in the middle of the process

    In the middle of one process, I want to invoke a java application. After the java application, the process will continue and select a path based on the result of the java application. Which activity can be used to invoke a java application in the middle of the process?
    Thanks

    BPM Changes:
    1. Under 'External Resources' create a new resource of type 'Server Configuration'. Specify the host port and path of your servlet here. This will be invoked from your process. Lets name this configuration as 'myExternalConf'.
    2. Create an interactive activity say 'InvokeMyApplication' in your process. The main task of this application should be external task. (Implementation Type = External)
    3. Create the prepareMethod method say 'prepareExternal'. Set the arguments for this method as output arguments. These arguments will be available to you in your external servlet.
    4. Create the commit method say 'commitExternal'. Set the arguments as input arguments. The external servlet will return these arguments back to the process.
    5. Check the 'Use configuration' checkbox for your main task (external task). Select 'myExternalConf' here.
    Servlet changes:
    When the user executes your 'InvokeMyApplication' activity, he will be taken to the external servlet of your external application. You will be passed the currentActivity, currentParticipant, instanceID and one more argument (which I dont remember :( ) as url parameters.
    1. In this servlet, open a PAPI/PAPI WS session for the participant passed to the servlet as url parameter
    2. Use the currentActivity ( passed in url parameter), to call prepare method on this activity. This will return you with the arguments defined in 'prepareExternal' method.
    3. Using these argumets, or otherwise, you can do whatever you want in this servlet. When done prepare the arguments to pass back to BPM.
    4. call papiService.activityCommit and return the arguments.
    5. Flow goes back to your BPM application
    Some code that might help:
    Servlet calling prerpare:
    ProcessServiceSession papisession = null;
    try{
    papisession = initializePapi();
    fuego.papi.Arguments args = fuego.papi.Arguments.create();
    args = papisession.activityPrepare(activity, instanceId, args);
    Map<String, Object> argsMap = args.getArguments();
    return argsMap;
    protected ProcessServiceSession initializePapi(){
    Properties configuration = new Properties();
    try {
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream("bpm.properties");
    if(inputStream == null)
    throw new IOException();
    configuration.load(inputStream);
    } catch (IOException ex) {
    log.log(Level.WARNING, "Could not load bpm.properties", ex);
    return null;
    Servlet calling commit:
    public void commitToALBPM(Map parameters){
    try{
    papisession = initializePapi();
    fuego.papi.Arguments args = fuego.papi.Arguments.create();
    Set s = parameters.keySet();
    Iterator propNames = s.iterator();
    while (propNames.hasNext()){
    String key = (String)propNames.next();
    String val = (String)parameters.get(key);
    args.putArgument(key, val);
    papisession.activityCommit(activity, instanceId, args);
    catch (OperationException e)
    HTH
    Satinder

  • How to upload a java application into the oracle DB

    Hello,
    I am in search of an issue that is worrying me now for weeks. I have a java application which is independent. Now I want to upload this application to the oracle DB.The idea is for the application to sit on the DB and do it work from there, which is to transfer data to another 3rd party independent system. What is the best way of doing this? Is there any utility which can help me to upload a java application to the DB?
    Also after uploading the application in the DB, how can it be called? Is there any tutorial to guide me please?
    Thank you all for brain storming

    Check the docs for "Java Stored Procedure":
    http://www.oracle.com/pls/db92/print_hit_summary?search_string=java+stored+procedure

  • How to execute a java application from java itself

    Hi,
    I�m working in Client Server environment. After starting the server, i want to automatically call the client. ( java Server (in Server.java
    the call (java Client) has to be done. Can anyone help me for this problem.
    thanks.

    In normal client server design the client initiates communication with the server, not the other way around.
    So you initiate a conversation just like a normal client server communication.
    -The client is running.
    -The client listens for a connection (SocketServer)
    -The server starts up.
    -It connects to the client using a socket. (The server must know the host/ip of the client.)

  • How to integrate a Java Application in the portal

    Hi:
    I have developed a pure and simple Java Application just like a test, only Java, no EJB, no JSP. JUST PURE JAVA. I need to put this application in my Oracle9iAS Portal and i've found something about developing EAR and WAR. But i can't find the way to put my app in the portal.
    Does anybody know how can i put my app in the portal? or what should i do?
    Thank you.

    Hi:
    I have developed a pure and simple Java Application just like a test, only Java, no EJB, no JSP. JUST PURE JAVA. I need to put this application in my Oracle9iAS Portal and i've found something about developing EAR and WAR. But i can't find the way to put my app in the portal.
    Does anybody know how can i put my app in the portal? or what should i do?
    Thank you.

  • How do I run java application on IIS server

    Hi,
    Can I run java application on IIS(Internet information Server)?
    If yes, How do i do that?
    My java application contains JSP,Servlets and EJB.
    To run java application on IIS which plug in should i use.
    Can anybody help me This is urgent...........
    Thanx

    Hi
    Check this article on JGuru. It explains how to use Tomcat together with IIS.
    http://www.jguru.com/faq/view.jsp?EID=776546
    If you also need to use EJB's you probably also want to have a JBoss installed - check www.jboss.org
    /Peter

  • Calling Java application in the server

    Hi,
    Is it possible to call a GUI based Java App from the oracle server? If so how?

    Hi,
    Welcome to MSDN.
    I would suggest you consider posting this issue in the forum Mr. Monkeyboy suggested.
    In addition, issues about java are not supported in these forums.
    Thanks for your understanding.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to manually completely remove a J2EE application from the server?

    Hello,
    I have created and deployed a certain test J2EE application.
    After I finished with it I wanted to remove it, yet I cannot do it: Any removal attempt, either by the SDM or Admin Tool, encounters exceptions and errors I cannot handle. I tried restarting the server, stopping the application yet nothing works. on telnet the application has always STOPPING ststus...
    Desperately, I have decided to manually remove this application from the server yet I don't know the steps.
    Can someone please give me a step-by-step guidance on how to completely remove this application from the server, so it won't appear anyome both at the SDM and at the deploy service of the WAS?
    Thank you in advance,
    Roy

    Hi Peter,
    I've reproduced the problem and created a thread dump. I believe these lines are the important ones:
    "SAPEngine_Application_Thread[impl:3]_10" prio=5 tid=0x080cc9d8 nid=0x18e0 in Object.wait() [8a8f000..8a8fdb8]
         at java.lang.Object.wait(Native Method)
         - waiting on <0x14450d88> (a java.lang.Object)
         at java.lang.Object.wait(Object.java:429)
         at com.sap.engine.services.ejb.EJBAdmin.destroyContainers(EJBAdmin.java:1145)
         - locked <0x14450d88> (a java.lang.Object)
         at com.sap.engine.services.ejb.EJBAdmin.commitStop(EJBAdmin.java:2529)
         at com.sap.engine.services.deploy.server.application.StopTransaction.commonCommitFinished(StopTransaction.java:262)
         at com.sap.engine.services.deploy.server.application.StopTransaction.commitCommon(StopTransaction.java:305)
         at com.sap.engine.services.deploy.server.application.StopTransaction.commit(StopTransaction.java:291)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:310)
         at com.sap.engine.services.deploy.server.application.ParallelAdapter.makeAllPhasesImpl(ParallelAdapter.java:327)
         at com.sap.engine.services.deploy.server.application.ParallelAdapter.runInTheSameThread(ParallelAdapter.java:111)
         at com.sap.engine.services.deploy.server.application.ParallelAdapter.makeAllPhasesAndWait(ParallelAdapter.java:230)
         at com.sap.engine.services.deploy.server.application.RemoveTransaction.begin(RemoveTransaction.java:133)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:292)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhases(ApplicationTransaction.java:326)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.makeGlobalTransaction(DeployServiceImpl.java:3139)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.remove(DeployServiceImpl.java:903)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.remove(DeployServiceImpl.java:5056)
         at com.sap.engine.services.deploy.server.DeployServiceImplp4_Skel.dispatch(DeployServiceImplp4_Skel.java:885)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:304)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:193)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:122)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Could you please advise how to proceed from here?
    Thank you in advance,
    Roy

  • How to schedule a java application via Windows Scheduler

    I can't figure out how to schedule a java application using the Windows Scheduler. Do I schedule the java application with the .class file as a parameter? How do I pass arguments to it?
    To execute FileCopy.class, my best guess was:
    Start | Control Panel | Performance and Maintenance | Scheduled
    Tasks | Add Scheduled Task | Browse | Program Files | Java |
    jre1.5.0_06 | ... Advanced Properties
    Under the Task tab:
    Run: "C:\Program Files\Java\jre1.5.0_06\bin\java.exe"
    Start In: "MyDocuments\Eclipse_Workspace\Java_File_Copy
    FileCopy"
    This does not work. How do I schedule the FileCopy.class java application, and how can I pass arguments to it? Can this be done without specifying a password?
    TIA,
    John

    Suppose that your class is FileCopy (has no package name) and is located under MyDocuments\Eclipse_Workspace\Java_File_Copy folder, then you should have:
    Run: "C:\Program Files\Java\jre1.5.0_06\bin\java.exe" FileCopy
    Start In: "MyDocuments\Eclipse_Workspace\Java_File_Copy"
    And yes you must provide a user password to execute the task.
    Best way to do this is to create a special user (with password) for executing this task.
    Regards

  • How to execute 2 different application from same Application Server

    Hi,
    I would like to know that how to execute two different applications from the same Application Server with different databases?
    We are using
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    Oracle Application Server 10g 10.1.2.0.2
    Regards,
    Hassan

    what type of applications you want to run from the same application server, Hassan?
    What other DB are you using to launch it beside the one you quoted? Is it the MRep DB of infra?

  • How can i run java application at system startup just liks as services

    How we can run java application at the time of system
    starts up just like as services.

    Hi,
    At first you have to create an exe of the class file.
    for that go to the site www.duckware.com/java2exe.html
    Click on the j2exe23c.exe(75k) download it and install in ur system. convert the class file to windows exe.
    The put the exe in the startup folder in windows.
    If ur not able to find that folder search for it and put that exe in that folder.

  • Java applications on EP server

    Hi EP Experts,
    I would like to know following things.
    1. How do I migrate Java applications on Portal server? (one way using JAVA PDK)
    2. What are the different problems that are faced during migration of Java code to EP server
    3. Do we need to import specific libraries that are used specific for Java applications and are not available with WAS/EP?
    If any one has similar migration experience please share the problems that are faced and if possible solutions you got for any.
    Thank you,
    Chintamani Chitnis

    Hi,
    Check this document
    http://help.sap.com/saphelp_erp2004/helpdata/en/88/bdfc3f48ecc742e10000000a1550b0/frameset.htm
    Regards,
    Ganesh N

  • Putting java programs to the server

    Is there any fast way/tutorial to put a java application to the server for multi users?
    Can it be done easily by using Eclipse?
    Can any one help me please?
    Thank you.

    It's silly to say that I'm very new to Java and Eclipse.
    Actually, I've done a project to update data for a company, and I need to find a way to put it into the company server. This program using Swing to show a GUI and allow one user update data at a time. Then data will be saved to file(configuration file), therefore, only one user can do it at a time.
    Please help me for any quick tutorial or sample codes which are similar to my job.
    Thank you.

  • How to make a Java application that will change the client box's IP address

    HI how to make a Java application( that application would be run on the client ) that will change the client box's IP address ( IP address of itself )

    If you can do that through the command line, then use Runtime.getRuntime().exec(...) to execute your command.

  • How can i let my java application closes the other opened windows

    how can i let my java application closes the other opened windows: like any other Microsoft Internet Explorer windows ... provided that my java application is not the one i used to open those other windows.... thanks in advance

    you'll have to use JNI to access the windowAPI
    then you need a list of window handles ... I think there was a function called getWindow and in order to close them you use sendMessage .... for details check out msdn (microsoft developer network)
    somwhere I saw a tool called JUtil, which might help you getting started on accessing the win api from java
    regards
    Spieler

Maybe you are looking for