Java 使用 Netbeans 创建 WAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9816783/
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-16 08:03:25  来源:igfitidea点击:

Creating WAR using Netbeans

javanetbeanswar

提问by user10101

I am creating war file from Netbeans. Previously I created jar file using Netbeans, it worked fine (in command prompt). But when I am running war file from command prompt, I am getting this error:

我正在从 Netbeans 创建War文件。以前我使用 Netbeans 创建了 jar 文件,它工作正常(在命令提示符下)。但是当我从命令提示符运行 war 文件时,我收到此错误:

Failed to load Main-Class manifest attribute from WebApplication2.war.

I have set main class from Netbeans during creation of jar

我在创建 jar 期间从 Netbeans 设置了主类

Project->properties->Run->Choosed main class)..

Do I have to set any mainclass during war creation (as web application does not have any main class, it just has JWS and servlets, how can we set main class)?

在创建War期间是否必须设置任何主类(因为 Web 应用程序没有任何主类,它只有 JWS 和 servlet,我们如何设置主类)?

回答by Jonathan S. Fisher

Think about what you're asking... A main class is the first class invoked when a user runs your app. What is the first class invoked when a user visits your webapp?

想想你在问什么......主类是用户运行你的应用程序时调用的第一个类。当用户访问您的 web 应用程序时调用的第一个类是什么?

It's going to be the classes bound to URLs inside your web.xml or bound with @Servlet annotations.

它将是绑定到 web.xml 中的 URL 或绑定 @Servlet 注释的类。

回答by Jigar Joshi

If your app is web project, Just say clean & build from Netbeans it will create a war file in your project/targetdirectory

如果您的应用程序是 Web 项目,只需从 Netbeans 说 clean & build 它将在您的project/target目录中创建一个 war 文件

回答by Jigar Joshi

Use web.xml to create an initial position for the war file to execute. Insert your welcome file in here

使用 web.xml 为要执行的 war 文件创建初始位置。在此处插入您的欢迎文件

 <root>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 </root>

This will automatically select the file to run initially.

这将自动选择最初运行的文件。