Netbeans no longer comes with Tomcat bundled so if you want to deploy your web application you need to manually register an external server.
foolish assumptions
I’m assuming you are using at least:
- Netbeans 12.0 installed and you are using Linux
- You have the Java Web Applications plugin installed.
- You know some basic terminal commands
If you don’t care an easier method would be to just download apache-tomcat.zip from the Tomcat website, extract the archive to a folder under your home directory and just skip to step 4 of this tutorial.
1. Installing Tomcat
sudo apt update
🙂 (the Linux ritual)
sudo apt install tomcat9 tomcat9-docs tomcat9-examples tomcat9-admin
Enter fullscreen mode Exit fullscreen mode
2. Add admin user in Tomcat
By default, Tomcat does have any users defined that could be used for administrative purposes, so we need to edit tomcat-users.xml
and add a user with the proper roles assigned to it.
sudo nano /etc/tomcat9/tomcat-users.xml
Enter fullscreen mode Exit fullscreen mode
Add the following lines in tomcat-users.xml
.
<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="username" password="_SECRET_PASSWORD_" roles="manager-gui" />
<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="username" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />
Enter fullscreen mode Exit fullscreen mode
3. Allow Netbeans to read the tomcat Configuration
Unfortunately Netbeans doesn’t correctly detect the the Tomcat installation directory.
We need to make sure that the configuration files can be read from the installation directory otherwise will get an error saying “The <CATALINA_HOME>/conf/server.xml can’t be read.”
sudo ln -s /etc/tomcat9/ /usr/share/tomcat9/conf
Enter fullscreen mode Exit fullscreen mode
We need to change permission on the Tomcat installation directory so we don’t face any permission issues.
sudo chown -R USERNAME /etc/tomcat9/
sudo chown -R USERNAME /usr/share/tomcat9/
Enter fullscreen mode Exit fullscreen mode
change
USERNAME
with your Linux username
4. Adding Server in Netbeans
Now that Tomcat is installed and configured we can open up Netbeans and under the Services tab right click on the Servers and click on Add server.
In the next window, select Apache Tomcat and click next.
Under Server Location
enter the tomcat directory,(where tomcat was installed). Also add your username and password that you used in the tomcat-users.xml
file.
Click finish, and you should see Tomcat as an added Server under the Server node.
Thanks for reading. I hope this is useful for you.
暂无评论内容