How to deploy to Tomcat from NetBeans?

感情迁移 提交于 2019-12-12 07:33:53

问题


I've added Tomcat in the "Tools > Servers" menu and as you can see it appears in the list of servers:

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?

The end: I've used the wrong archetype so that NetBeans decided that Tomcat is not capable to execute it.


回答1:


When you create a Maven based web app project, you specify the spec version of the project as you create it.

image of the Maven web App Wizard with default values 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.

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




回答2:


Is your webapp a real Java EE 6 webapp (without web.xml or with a 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).




回答3:


Go into your web.xml and replace the header with:

<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




回答4:


Add this to your pom.xml after: <repositories></repositories>

<properties>
        <netbeans.hint.deploy.server>Tomcat60</netbeans.hint.deploy.server>
</properties>



回答5:


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?




回答6:


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.

I created manually because I couldn't find a good archetype, could you please post the place where you got the good Tomcat archetype?




回答7:


I had the same problem and solved it ;

It was because the Java EE version was higher than the tomcat version requires.

What to do :

Click the files tab near projects tab. Under nbproject folder , 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 .

Now the server will come at Project > properties > Run > Servers




回答8:


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.




回答9:


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


来源:https://stackoverflow.com/questions/2781057/how-to-deploy-to-tomcat-from-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!