开发者

problem with running a java web application on command prompt

i have a simple proje开发者_StackOverflow中文版ct where there is a html file as view, a servlet as controller and few java files as models. The java files contain some information that need to be printed on console. I have been able to compile the classes successfully.How do i run it from command prompt so that the output appears on console


You will need to create a web.xml file and archive all the files into a .war file. Then you can deploy that .war file to Tomcat. Tomcat will write all your System.out.println() stuff to catalina.out.

Alternatively, you can create a new Java class with a main() method that calls the parts of your code that write to the console. You can then run that class as you would normally run a Java application in the console.


If you are already building a WAR file (Web Application Archive) and you are using Maven for a build tool, you can use the maven-jetty-plugin. It is very easy to configure. It will allow you to run a command from a command prompt (or shell) like:

mvn jetty:run

It will run your webapp from a console and print all logs messages to that console. You kill the process with the standard Ctrl+C shortcut.

If you are not using Maven, you can still use Jetty as a web server, it just takes a bit more work. It is very lightweight either way though but this wouldn't be much different than using tomcat or any other servlet containers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜