简体   繁体   English

如何通过 javac 编译一个 java web 应用程序?

[英]How to compile a java web application by javac?

I have a traditional Java web project, it's structure displayed as below我有一个传统的 Java web 项目,它的结构如下所示

|-lib
|-src
   |-main
      |-java
      |-resources
|-wbeapps
   |-WEB-INF
      |-web.xml

I compile and run this application by IDEA's tomcat configuration before, all the issues about compile, run and deploy is done by IDEA.之前我是通过IDEA的tomcat配置来编译运行这个应用的,编译、运行、部署的所有问题都由IDEA来完成。

Now, I must modify a java file of src\\main\\java\\xxx , and this modification is absolutely correct, then not using IDEA or Eclipse to achieve the compilation and deploy to Tomcat.现在,我必须修改一个src\\main\\java\\xxx的java文件,而且这个修改是绝对正确的,那么就不用IDEA或者Eclipse来实现编译部署到Tomcat了。

How can I do that without IDEA or Eclipse, just use javac or other tools?如果没有 IDEA 或 Eclipse,我怎么能做到这一点,只需使用 javac 或其他工具? Please give me some advices, thanks.请给我一些建议,谢谢。

You're going to need to have a war (web application archive) file if you want to deploy to Tomcat.如果您想部署到 Tomcat,您将需要一个 war(Web 应用程序存档)文件。 To generate a war file, first, compile all of your files using javac, and then run the jar command:要生成一个 war 文件,首先,使用 javac 编译所有文件,然后运行 ​​jar 命令:

jar -cvf project.war * 

This command should be run from the root project directory (not inside WEB-INF or any other folders).此命令应从项目根目录(不在 WEB-INF 或任何其他文件夹中)运行。

The -c option specifies that you want to create a file, the -v option will generate verbose output, and the -f option allows you to specify the archive name. -c 选项指定您要创建文件,-v 选项将生成详细输出,-f 选项允许您指定存档名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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