Development with NetBeans (deprecated)
This guide was first written to explain how to use Liferay package with the Tomcat instance bundled with NetBeans. Unfortunately the auto-deployment required for rapid development did not work in this case. So this guide is left here as a reference how the bundled Tomcat application works, and how to enable Liferay portlet server on that instance.
Please refer to this page for actual working setup.
Install NetBeans with Tomcat
Download the NetBeans Java EE version from NetBeans site. When installing, make sure that the Install Apache Tomcat server option is selected.
Test the installation
- Start NetBeans and choose Services –> Servers.
- If NetBeans asks for a master password, enter or create it.
- Right-click on Apache Tomcat server entry and choose Start. The server is started on port 8084.
- The http://localhost:8084 should display the Tomcat welcome screen.
Although Tomcat is installed into some system-wide folder, NetBeans creates private profile for each user’s private configuration directory under user’s profile.
Under Linux it is located on ~/.netbeans/[version]/apache-tomcat-[version]_base
In Windows it is something like C:\Users\[username]\.netbeans\[version]\apache-tomcat-[version]_base
All further configuration will be done in that directory.
The default Tomcat installation requires support libraries for Liferay to run properly. These can be extracted from the Liferay Apache Tomcat Bundle.
Extract it, and copy the whole tomcat7/lib/ext directory to the Tomcat configuration directory specified above. Rename the copied ext directory to lib. There is no existing lib directory, but Tomcat instance looks for it and loads the libraries from that path as well.
Download the WAR file from Liferay download site and copy it into the webapps folder located under private Tomcat configuration directory specified above.
Additional NetBeans Configuration
Enable Tomcat autodeploy
By default Tomcat’s NetBeans instance does not extract and deploy the installed WAR-files. To enable automatic deployment:
- In NetBeans choose Services –> Servers.
- Right-click on Apache Tomcat server entry and choose Edit server.xml.
- Locate the following line and change the autoDeploy flag to true:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
Expand memory limits
Tomcat will most probably run out of memory when initializing Liferay portal. Therefore the Tomcat instance must be reconfigured to allow bigger memory allocations.
- In NetBeans choose Services –> Servers.
- Right-click on Apache Tomcat server entry and choose Properties.
- Select the Platform tab.
- First make sure that Tomcat uses 64-bit Java platform. The 32-bit JVM cannot handle bigger allocations than approximately 1.4 GB which sadly is not enough. The platforms can be added by the Manage Platforms button.
- If using 64-bit Java, then into the VM Options field add:
-Xms2048m -Xmx2048m -XX:MaxPermSize=1024m
Now start the Tomcat server from Services –> Servers by right-clicking on it and choosing Start.
The Tomcat starts, finds the Liferay WAR-file, unpacks it and initializes the environment.
- The web interface should be seen on http://localhost:8084
- The Liferay instance can be accessed from http://localhost:8084/liferay
If there are any out of memory errors, then update the VM Options field to allow even bigger allocations.
Finish Liferay setup
Since Liferay portal is located directly under Tomcat’s web root, the Liferay context must be fixed so that the generated URLs will have correct prefix.
This can be easily verified by the visual UI from the previous step. If Liferay setup screen looks ugly, it means the context is wrong.
It can be updated by creating the following file webapps/liferay/WEB-INF/classes/portal-ext.properties:
As a reminder the webapps directory is located under .netbeans/[version]/apache-tomcat-[version]_base under current user profile.
Note: Please don’t delete the WAR file or Tomcat will undeploy and delete the Liferay component from webapps directory. To delete the archive, first turn autodeploy off again. If the Liferay is redeployed, the portal-ext.properties file must be regenerated manually again.
Now restart the Tomcat and the Liferay context should be fixed and Liferay setup screen look fine.