0

I made a Java ServLet using NetBeans and it's working great but the problem is that I need to run my ServLet through NetBeans using the Run button.

I no longer want to do this. I want to run it without NetBeans. I want to make a standalone ServLet. So I used to the Build option which generated a .war file of my ServLet but I do not know what to do with this file. How can I run this file and use my ServLet? I don't want to seen running the file each time via NetBeans in front of other people. It seems so unprofessional.

Please help. Thank you.

user5793353
  • 33
  • 2
  • 7
  • Checkout this post: [How do I run a class in a WAR from the command line?](http://stackoverflow.com/questions/1842972/how-do-i-run-a-class-in-a-war-from-the-command-line) – lachty Jan 15 '16 at 07:12
  • pls check this, [Creating executable war](http://stackoverflow.com/questions/20491407/create-a-executable-jar-using-maven-and-jetty) – jos Jan 15 '16 at 07:20

2 Answers2

0

war file, unlike a jar file needs to be deployed in a servlet container. e.g.: Tomcat, Jetty. It's not supposed to be run via the command line. If you do want to run it via the command line, you would probably need to take care of starting up the servlet container yourself. e.g.: start jetty server instance from code and deploy your war inside it.

Dev Blanked
  • 8,555
  • 3
  • 26
  • 32
  • Thanks, I will be using GlassFish since that's what NetBeans uses inside. Can I do it so that the server can start when my PC starts and I can just use my browser to directly go into my server page? – user5793353 Jan 15 '16 at 07:31
0

You need to create a war file that contains different parts. It needs at least a web.xml that describes the application. It is not here the right place to write a tutorial on java webapp, but there are thousands on internet.

The war file then can be deployed on a servlet container such as Apache Tomcat.

Marco Altieri
  • 3,726
  • 2
  • 33
  • 47