Java 如何在 NetBeans 中创建我的项目的 war 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1007346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:12:13  来源:igfitidea点击:

How can I create a war file of my project in NetBeans?

javajspnetbeans

提问by user93796

How can I create a war file of my project in NetBeans?

如何在 NetBeans 中创建我的项目的 war 文件?

采纳答案by steve

It's possible that you already have a war file and don't know it - netbeans does most of the work for you and I believe it creates a distributable war file by default. If you created a web project and successfully built it, it will be in the "dist" directory off your project root.

您可能已经有一个 war 文件但不知道它 - netbeans 为您完成了大部分工作,我相信它默认会创建一个可分发的 war 文件。如果您创建了一个 Web 项目并成功构建了它,它将位于项目根目录下的“dist”目录中。

回答by DMMcKinnon

Netbeans will create the Ant script for you, it uses Ant to build anyway. But if you want to get the war file, just build your project. The .war file will be located in /yournetbeanshomedirectory/yourproject/dist/yourwar.war

Netbeans 将为您创建 Ant 脚本,它无论如何都使用 Ant 来构建。但是如果你想获得war文件,只需构建你的项目。.war 文件将位于 /yournetbeanshomedirectory/yourproject/dist/yourwar.war

You can check out the ant build script it uses by looking at the build.xml file in your project directory. Might help you feel a little more comfortable using ant to do builds.

您可以通过查看项目目录中的 build.xml 文件来查看它使用的 ant 构建脚本。使用 ant 进行构建可能会帮助您感觉更舒服一些。

回答by Kaushik Gopal

Right click your project, hit "Clean and Build". Netbeans does the rest.

右键单击您的项目,点击“清理并构建”。Netbeans 完成剩下的工作。

under the distdirectory of your app, you should find a pretty looking .war all ready for deployment.

在您的应用程序的dist目录下,您应该会找到一个漂亮的 .war 文件,可以部署了。

回答by DPA

I had to right-click the build.xml file and choose "run". Only then would the .war file be created.

我必须右键单击 build.xml 文件并选择“运行”。只有这样才会创建 .war 文件。

回答by Yuri Ghensev

If NetBeans haven't created your distfolder, execute the do-distant target:

如果 NetBeans 尚未创建您的dist文件夹,请执行do-distant 目标:

In commandline navigate to the directory of your project, the one containing a build.xml file
> ant do-dist

If ant runs fine (most likely), your distfolder will be created, containing the .warfile.

如果 ant 运行良好(很可能),您的dist文件夹将被创建,其中包含该.war文件。

回答by Salvador Valencia

As DPA says, the easiest way to generate a war file of your project is through the IDE. Open the Files tab from your left hand panel, right click on the build.xml file and tell it what type of ant target you want to run.

正如 DPA 所说,生成项目 war 文件的最简单方法是通过 IDE。从左侧面板打开 Files 选项卡,右键单击 build.xml 文件并告诉它您要运行哪种类型的 ant 目标。

NetBeans - Create a WAR file

NetBeans - 创建 WAR 文件

回答by superUser

Just check in you projects properties >build ->packaging WAR file compress.

只需检查您的项目属性>build ->packaging WAR file compress。

回答by Barani r

Simplest way is to Check the Output - Build tab: It would display the location of war file.
It will have something like:

最简单的方法是检查输出 - 构建选项卡:它会显示战争文件的位置。
它会有类似的东西:

Installing D:\Project\target\Tool.war to C:\Users\myname.m2\repository\com\tool\1.0\Tool-1.0.war

安装 D:\Project\target\Tool.war 到 C:\Users\myname.m2\repository\com\tool\1.0\Tool-1.0.war

回答by Fusca Software

It is in the dist folder inside of the project, but only if "Compress WAR File" in the project settings dialog ( build / packaging) ist checked. Before I checked this checkbox there was no dist folder.

它位于项目内部的 dist 文件夹中,但前提是项目设置对话框(构建/打包)中的“压缩 WAR 文件”被选中。在我选中此复选框之前,没有 dist 文件夹。

回答by jmojico

This worked for me:

这对我有用:

1.Right click pom.xml
2.Run Maven > Goals
3.Edit maven goals

1.右键单击 pom.xml
2.运行 Maven >目标 3.
编辑 Maven 目标

enter image description here


Edit maven goals

在此处输入图片说明


编辑 Maven 目标

Results: war build in /target folder

结果: /target 文件夹中的战争构建

   Packaging webapp
    Assembling webapp [WeatherDashboard] in [C:\Users\julian.mojico\Documents\NetBeansProjects\WeatherDashboard\target\WeatherDashboard-1.0-SNAPSHOT]
    Processing war project
    Webapp assembled in [672 msecs]
    Building war: C:\Users\julian.mojico\Documents\NetBeansProjects\WeatherDashboard\target\WeatherDashboard-1.0-SNAPSHOT.war
    ------------------------------------------------------------------------
    BUILD SUCCESS
    ------------------------------------------------------------------------
    Total time: 1:41.633s
    Finished at: Tue Sep 05 09:41:27 ART 2017
    Final Memory: 18M/97M
    ------------------------------------------------------------------------