Java 如何从 NetBeans 部署到 Tomcat?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2781057/
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
How to deploy to Tomcat from NetBeans?
提问by deamon
I've added Tomcat in the "Tools > Servers" menu and as you can see it appears in the list of servers:
我在“工具 > 服务器”菜单中添加了 Tomcat,如您所见,它出现在服务器列表中:
But when I try to run my project, I cannot select Tomcat! The drop-down with servers is empty. I tried it with NetBeans 6.8 and 6.9 Beta. Any idea?
但是当我尝试运行我的项目时,我无法选择Tomcat!服务器下拉列表为空。我在 NetBeans 6.8 和 6.9 Beta 上进行了尝试。任何的想法?
The end: I've used the wrong archetype so that NetBeans decided that Tomcat is not capable to execute it.
最后:我使用了错误的原型,因此 NetBeans 认为 Tomcat 无法执行它。
采纳答案by vkraemer
When you create a Maven based web app project, you specify the spec version of the project as you create it.
创建基于 Maven 的 Web 应用程序项目时,请在创建项目时指定项目的规范版本。
带有默认值的 Maven Web 应用程序向导的图像 http://www.freeimagehosting.net/uploads/20d7e476a5.png
If you want to create a project that you can deploy with Tomcat, you need to change the value of the 'Java EE Version' field from 'Java EE 6' to 'Java EE 5', before you hit the Finish button.
如果要创建可以使用 Tomcat 部署的项目,则需要在点击“完成”按钮之前将“Java EE 版本”字段的值从“Java EE 6”更改为“Java EE 5”。
Note: I had hoped that there was a simple change that could be applied to your projects pom file to convert it from Java EE 6 to Java EE 5... but it turns out that it is not so easy...
注意:我曾希望有一个简单的更改可以应用于您的项目 pom 文件以将其从 Java EE 6 转换为 Java EE 5……但事实证明这并不容易……
回答by Stian
If you right-click the project, select Properties and go to Run, there should be a dropdown list of servers. Is that one empty as well?
如果您右键单击该项目,选择“属性”并转到“运行”,应该会有一个服务器下拉列表。那个也是空的吗?
回答by Pascal Thivent
Is your webapp a real Java EE 6 webapp (without web.xml
or with a Servlet 3.0 web.xml
)?
您的 webapp 是真正的 Java EE 6 webapp(没有web.xml
或有 Servlet 3.0 web.xml
)吗?
If yes, maybe NetBeans doesn't show Tomcat because Tomcat is not a valid runtime environment for your application (use GlassFish).
如果是,则 NetBeans 可能不会显示 Tomcat,因为 Tomcat 不是您的应用程序的有效运行时环境(使用 GlassFish)。
回答by Amala
I had this exact same issue, when creating a default EE project in Netbeans it does a full EE spec which Tomcat doesn't fulfill.
我遇到了完全相同的问题,在 Netbeans 中创建默认 EE 项目时,它执行了 Tomcat 无法满足的完整 EE 规范。
I created manually because I couldn't find a good archetype, could you please post the place where you got the good Tomcat archetype?
我手动创建的,因为我找不到好的原型,你能把你得到好的 Tomcat 原型的地方贴出来吗?
回答by walnutmon
Go into your web.xml and replace the header with:
进入您的 web.xml 并将标题替换为:
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Go back to properties and you will be able to pick Tomcat
返回属性,您将能够选择Tomcat
回答by asanchez
Add this to your pom.xml
after: <repositories></repositories>
将其添加到您的 pom.xml 之后: <repositories></repositories>
<properties>
<netbeans.hint.deploy.server>Tomcat60</netbeans.hint.deploy.server>
</properties>
回答by DrFlash
One of the mistakes I was making when I got this problem was that I was trying to deploy EAR project to Tomcat. Tomcat isn't an application server. It is a web server. It worked when I deployed the only the Web project of the EAR to Tomcat. The ejb can only be deployed to an application server.
I hope this helps.
当我遇到这个问题时,我犯的错误之一是我试图将 EAR 项目部署到 Tomcat。Tomcat 不是应用程序服务器。它是一个网络服务器。当我将 EAR 的唯一 Web 项目部署到 Tomcat 时,它起作用了。ejb 只能部署到应用服务器。
我希望这有帮助。
回答by Kaan
I had the same problem and solved it ;
我遇到了同样的问题并解决了它;
It was because the Java EE version was higher than the tomcat version requires.
这是因为Java EE 版本高于tomcat 版本要求。
What to do :
该怎么办 :
Click the files tabnear projects tab. Under nbprojectfolder , select j2ee.platform, if you use Tomcat7 than change the platform to 1.6 for example(Tomcat6 > Jave EE 1.5). than make a "clean and build" on the project .
单击项目选项卡附近的文件选项卡。在nbproject文件夹下,选择j2ee.platform,如果您使用Tomcat7,则将平台更改为 1.6 例如(Tomcat6 > Jave EE 1.5)。而不是在项目上进行“清理和构建”。
Now the server will come at Project > properties > Run > Servers
现在服务器将位于 Project > properties > Run > Servers
回答by daschapa
A more updated "web-app" should look like this.
更新后的“网络应用程序”应如下所示。
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_1.xsd">