简体   繁体   中英

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

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

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.

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.

NetBeans - 创建 WAR 文件

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

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

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 /you.netbeanshomedirectory/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.

This worked for me:

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

在此处输入图像描述


编辑 Maven 目标

Results: war build in /target folder

   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
    ------------------------------------------------------------------------

If NetBeans haven't created your dist folder, execute the do-dist ant target:

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 dist folder will be created, containing the .war file.

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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