简体   繁体   中英

Call from java Main class from servlet Application

I Have two applications.One is Standalone application.Another one is web Application (Servlet App). Here I want to Call Java Application From Servlet Application.So can You Guys Suggest Me or Can i have one app for this one.So that i will implement in my application. In this Application I have created Jar file of Stand alone Application After that What to do ?

First, you should make your command line application classes available in your web applcaction environment. To achieve this you should either:

  1. package all in one jar
  2. put classes of stand alone application under WEB-INF/classes in you war
  3. put jar that contains your stand alone application under WEB-INF/lib in you war

Stand alone application starts from main() method. You can just call this method from your servlet and pass parameters, for example: MyApp.main("hello", "stand alone application") .

Since you are the author of both applications and are familiar with the internal design of the stand alone application you could (and probably should) call internal layer directly without using main() . For example if you main method starts with new MyApp().start() perform the same call from your servlet.

只需从GlassFish切换到Tomcat,即可解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM