Trying to build from the command line, and produce a WAR file

巧了我就是萌 提交于 2019-12-01 09:47:36

Your code depends on the servlet API which is not in the core Java library. You will need to add it to your classpath:

javac -classpath $TOMCAT_HOME/lib/servlet-api.jar yourpackage/HelloWorld.java

WARs share the same file format as JARs (ZIP with UTF-8 filenames.) Generally, you can use ZIP utilities to work with them.

A WAR structure might look like this:

index.html
foo.jsp
WEB-INF/classes/yourpackage/HelloWorld.class
WEB-INF/web.xml

The above assumes you have a package yourpackage; declaration in your .java file. The default package should be avoided.

If this is just a toy project it may not be worth your while, but I suggest that you adopt a serious build tool as keeping track of all the libraries you need is soon going to become an unmanageable task. The one I use is Maven, but there are alternatives.

You must to use jar command and to add dependencies to classpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!