Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

macos - How to connect NetBeans 8 with Tomcat 8 in Mac OS X?

I found other Questions and Answers dealing with getting the NetBeans IDE to talk to the Apache Tomcat servlet container. But they seem to be out of date or involve extraneous steps. I remember the process as being less complicated on my Mac. But I cannot remember the exact steps.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Indeed, getting Tomcat to talk to NetBeans is fairly simple though not obvious.

Java EE edition of NetBeans

If downloading NetBeans, grab an edition of NetBeans IDE already bundled with Tomcat. You may need to customize the installation to get Tomcat, as described in this Question.

screen shot of downloading edition of NetBeans IDE with Tomcat bundled

But that version of Tomcat is likely to be out of date. So let‘s look at hooking up a fresh copy of Tomcat with NetBeans IDE.

File Permissions

First be sure your copy of Tomcat can run. The permissions by default usually do not allow execution, at least in my experience on a Mac. So reset the permissions. If you are a Unix whiz, you can do so in the command-line. The rest of us use the BatChmod app.

enter image description here

I turn on all the checkboxes except Clear xattrs.

screenshot of BatChmod app setting Unix file permissions on Tomcat folder

Verify that Tomcat can run by executing the startup.sh file in Tomcat’s bin folder. Point your web browser to http://localhost:8080/ to see a Tomcat page. Then run shutdown.sh to quit Tomcat.

Tip: You may delete all the files ending in .bat. Those are "batch" files used only on Microsoft Windows. Mac OS X uses the Unix files ending in .sh instead.

Define a Server in NetBeans

In the Services pane, context-click on the Servers item. From the context menu, choose Add server.

enter image description here

Big NetBeans Tip: When in doubt, context-click. While the Mac convention is to provide a main menu item for every item with context-menu being a mere convenience, NetBeans depends heavily on context-menus.

In the dialog that appears, choose Apache Tomcat or TomEE. Type a name to be displayed in NetBeans list of "Servers". I suggest typing "Tomcat" plus the version number.

enter image description here

Click Next for the next panel of this Add Server Instance wizard.

enter image description here

Tomcat Location

Click the Server Location > Browse button, and choose where your Tomcat folder. I keep mine in my "home" folder.

Deployment Location

Turn on the Use Private Configuration Folder checkbox.

We need to choose a folder where we want Tomcat (specifically, Tomcat’s Catalina module) to do its work, keep its temporary files, keep its logs, and place the installed copy of your web app when you run from within NetBeans. You must create this folder. The folder’s location can be anywhere. For its bundled version of Tomcat, NetBeans uses a folder nested in ~/Library/Application Support. But I tend to create a folder in my home folder with a nested folder for each version of Tomcat, ~/Apache-Tomcat-Netbeans/8.0.27/ for example. Unix & Java tend to get cranky about spaces in file paths, so I use hyphens rather than spaces in those folder names.

Click the Cataline Base > Browse button to display a file picker. Use the Create New Folder icon button in the upper right corner to create the folder hierarchy you want to use for your web app’s deployment when run from NetBeans (as discussed in previous paragraph).

enter image description here

Tomcat Manager User

Lastly in that panel, make up a user name and password to be used as a Tomcat "manager" to startup and shutdown Tomcat. Be sure to check the Create user if it does not exist checkbox.

The wizard panel should look something like this screen shot.

enter image description here

Click the Finish button. And voilá, you have a new Tomcat server defined within NetBeans.

enter image description here

The last step is to tell your project to use that server.

In your project’s Properties dialog, set Build > Run > Server (popup menu) to your newly defined server.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...