Spring Portlet MVC Framework is shipped with the official Spring distro. From the samples directory you can access the "petportal" project which uses ant for building purposes. The portal is composed of several portlets =, take a look at portlet.xml there.
I will mavenize, build and deploy in Liferay-on-Glassfish the PetPortal project.
No need to explain why Maven.
I have said before that I like separation of concerns and I believe an IDE should be just to write and debug code. Running a Server inside an IDE makes at least myself slower. I will be using then a remote Liferay Portal running on Glassfish. I will be deploying there the results of the Maven build.
Mavenize Pet Portal
- Download Spring Framework. I will be using 2.5.6.
- Run these commands. You need to change the location of the original project sample.
```
PET=/Users/nurquiza/Downloads/spring-framework-2.5.6.SEC01/samples/petportal/
mkdir ~/mavenized-pet-portal
cd ~/mavenized-pet-portal
mkdir -p src/main/java
mkdir -p src/main/resources
mkdir -p src/main/webapp
mkdir -p src/test/java
mkdir -p src/test/resources
cp -R $PET/src/* src/main/java/
cp -R $PET/war/* src/main/webapp/
vi pom.xml
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
com.nestorurquiza.tutorials
mavenized-pet-portal
war
1.0.0-SNAPSHOT
javax.servlet
jstl
1.2
org.springframework
spring-webmvc
${spring.version}
commons-fileupload
commons-fileupload
1.2.1
org.springframework
spring-webmvc-portlet
2.5.6
log4j
log4j
1.2.14
provided
portlet-api
portlet-api
provided
1.0
junit
junit
4.5
test
com.springsource.repository.bundles.release
SpringSource Enterprise Bundle Repository - SpringSource Releases
http://repository.springsource.com/maven/bundles/release
com.springsource.repository.bundles.external
SpringSource Enterprise Bundle Repository - External Releases
http://repository.springsource.com/maven/bundles/external
com.springsource.repository.bundles.snapshot
SpringSource Enterprise Bundle Repository - Snapshot Releases
http://repository.springsource.com/maven/bundles/snapshot
package
mavenized-pet-portal
org.apache.maven.wagon
wagon-webdav
1.0-beta-2
maven-compiler-plugin
2.0.2
1.6
1.6
org.codehaus.mojo
buildnumber-maven-plugin
validate
create
{0,date,yyyy-MM-dd HH:mm:ss}
timestamp
org.apache.maven.plugins
maven-war-plugin
2.0.2
true
${buildNumber}
scm:svn:http://your.repository.domain/path/to/tags/directory
scm:svn:http://your.repository.domain/path/to/tags/directory
scm:svn:http://your.repository.domain/path/to/tags/directory
2.5.6
1. Build the project
cd ~/mavenized-pet-portal
mvn install
1. Confirm your remote liferay server is up and running. I use an external VirtualBox Ubuntu 64 bits VM with a Glassfish server running Liferay. In my hosts file I have pointed to the at server IP using alias liferay-glassfish-server:
http://liferay-glassfish-server:8080
1. Deploy the pet portal (as I said it contains several portlets). I am using scp command to deploy. The Ubuntu-Liferay-Glassfish username is liferay and the remote portlet deployment folder is ~/portlet:
scp target/mavenized-pet-portal.war liferay@liferay-glassfish-server:~/liferay-plugin-deploy/
1. Login to Liferay and include one of the portlets for example "Pet Sites" to confirm the deployment went succesfully.
1. Import or commit your project. I use subversion. Note the target directory and all hidden files are excluded. You do not want specific IDE files for example to be committed to SVN.
1. Generate IDE specific project files. I will show Eclipse specifics here but you can use any IDE of course.
cd ~/mavenized-pet-portal
mvn eclipse:clean
mvn eclipse:eclipse
1. Install the appropriate maven plugin in your IDE. Here are the specifics for Eclipse ...
1. Import the project as a Maven project. Be sure option "Menu | Project | Build automatically is set"
1. From the admin console (http://liferay-glassfish-server:4848/) Go to Configuration | JVM Settings and check the "Debug Enabled" checkbox. Hit Save. Alternatively from command prompt start as:
asadmin start-domain --debug
1. ssh into the Glassfish box and restart the server
1. Connect to the remote debugging port from Eclipse following these steps: Menu; Run; Debug Configurations; Right click on Remote Java Application; New; name it as liferay-glassfish-server; Host=liferay-glassfish-server; Port=9090. Apply and save. From now on you can click on Debug icon and select liferay-glassfish-server option to connect to Galssfish JVM debug port. Alternatively use command prompt ;-)
jdb -attach liferay-glassfish-server:9009
```
1. Put a breakpoint in line 52 of PetSitesEditController.
1. From Liferay interface go to the Pet Sites Portlet and click on "Add Site". Eclipse stops execution at the breakpoint.
Some common tasks
- Undeploy the portlet: Login to http://liferay-glassfish-server:4848 and from Applications menu select the portlet to be removed, then press undeploy.
tags:Maven spring mvc portlet tutorial