Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When tomcat starts...

 
Aditya Raghu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I need to run a script as soon as tomcat starts each time (In Linux). Can you please suggest a way in which this can be done?

Thanks
Aditya



 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Raghu wrote:I need to run a script as soon as tomcat starts each time (In Linux).

Whats the script do ? Is it needed for running a Java web app ? If yes then I suggest try implementing ContextListener for that web app. If not, then we've to wait for experts comment

And welcome to JR.
 
Aditya Raghu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply sagar . Well, I want to run a java jar which is a swing applet.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to study java.lang.Runtime -or- ProcessBuilder - which allow you to execute separate processes, such as executing a script.

As Sagar said, a ContextListener would be one place to execute your script.

Carefully read the Process docs with respect to the requirement for handling standard IO streams.

Bill
 
Aditya Raghu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to run a swing application jar. I can run the application from an ordinary '.sh' file, but I'm not able to run the jar from startup.sh. I used this command at the end of the startup.sh file- 'java -jar frontend2.jar'. when i run startup.sh it starts tomcat properly but does nothing with the jar. Is this the right way to do this? I even tried calling another shell file from startup.sh, where I was running the jar but, even that did not work.

Please guide me on this...
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Raghu wrote: Well, I want to run a java jar which is a swing applet.

Well applet can be run by embedding them into JSP/HTML file, not by executing them within the Tomcat startup script, which is unusual thing to try !!!
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:Well applet can be run by embedding them into JSP/HTML file, not by executing them within the Tomcat startup script, which is unusual thing to try !!!


"Unusual"... yes, that's the polite way to say it. I can't imagine any reasonable design which would require running an applet on the server at start-up time, or at any other time for that matter. I expect there has been some misunderstanding and this is not the actual requirement.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Sagar Rohankar wrote:Well applet can be run by embedding them into JSP/HTML file, not by executing them within the Tomcat startup script, which is unusual thing to try !!!

I expect there has been some misunderstanding and this is not the actual requirement.

I don't misunderstood anything, the OP has the requirement,

Aditya Raghu wrote:I want to run a swing application jar. I can run the application from an ordinary '.sh' file, but I'm not able to run the jar from startup.sh. I used this command at the end of the startup.sh file- 'java -jar frontend2.jar'. when i run startup.sh it starts tomcat properly but does nothing with the jar. Is this the right way to do this? I even tried calling another shell file from startup.sh, where I was running the jar but, even that did not work.

and which is, as you said, no matter reasonable or correct.
 
Aditya Raghu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok I am very new to web development, but please bear with me . Here is my problem statement- I have a web application war in my web apps. I have to get tomcat run the war only when a proper license is submitted( licensing mechanism is not built yet). I have been asked to run the application from the present in the webapps folder based on the above condition. Is it possible in tomcat to configure and run an application selectively because here all other wars in the webapps folder should be left untouched.

Thanks
Aditya
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application war in my web apps.


If this is really a web application accessed by a HTTP request through Tomcat and generating a HTTP response, then normal web application security should apply.

Swing applications are "desktop" applications with a graphic user interface, not accessed by an HTTP request and not hosted by Tomcat but by the native operating system. If you contrive to start a Swing application on the server, only the server desktop interface can interact with it.

So - is the application a web application with HTTP or a desktop application?

Now, it is possible for Tomcat to control downloading of a desktop application - see the Java JNLP and Web Start forum.

Bill
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Raghu wrote:I have to get tomcat run the war only when a proper license is submitted( licensing mechanism is not built yet).

No, you shouldn't supposed play with tomcat if you can fulfil you needs simply by putting some licensing logic in web app.

Here are my 2 quick solutions:

  • 1. Deploy and check for the licence:
    Deploy the war, and show the "Upload your license" page, once user has uploaded it and you verify it, allow him to access the other protected pages, which need valid licence.


  • 2. Don't deploy war at all:
    Implement the context listener, which will check for the .lic file which is nothing but the encrypted license file. Once verified deploy the war otherwise exit


  • Now this two things require a good knowledge of Java web application working.. and about other method, lets fellow Ranchers provide their inputs
     
    Aditya Raghu
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    # 2. Don't deploy war at all:
    Implement the context listener, which will check for the .lic file which is nothing but the encrypted license file. Once verified deploy the war otherwise exit


    Thanks a lot for that Sagar. If you can, can you please briefly tell me how that can be done? I searched a lot for it but found very little on how a war can be exited in the servletcontextlistener implementation.

    Thanks,
    Aditya
     
    Sagar Rohankar
    Ranch Hand
    Posts: 2907
    1
    Java Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Google ServletContextListener example
    In contextInitialized () method,
     
    Tim Holloway
    Saloon Keeper
    Pie
    Posts: 18092
    48
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You don't want to use Swing to natter about WAR licensing. On my production servers, that will fail because I don't run them with a GUI. Which gives me about and extra 100MB of RAM for webapps.

    In most cases, I'd go ahead and let the webapp run in demo mode, but block the ability for it to do serious work. It's a very effective marketing strategy. If your app looks good enough, people are more willing to pay to unlock it if they can see it running.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic