Thursday, 12 June 2014

Setting up Spring MVC flavor of AppFuse 3.0.1-SNAPSHOT stack in Eclipse IDE

Hello again! I was lucky enough to review some of the web application stacks and have found AppFuse Stack a comprehensive starter kit with well-written tutorials to continue with. I have used them in couple of projects in past successfully especially with Spring MVC Flavor and I thought I would write some tutorials dedicated to this Stack. To learn more on AppFuse, click on.

In this tutorial, I will show in 5 steps to generate, import and start up Spring MVC flavor of AppFuse ready for development in your Eclipse IDE with the following pre-requisites:

1. Eclipse IDE  (JUNO or later) with m2e plugin installed.
2. Maven 3.x
3. MySQL 5.x
4. JDK 7.x
5.  An awesome Macbook Pro on Maverick OSX or whatever OSX Version you currently have.
6. and of course Internet Connection

Step 1: Generate your choice of stack with AppFuse QuickStart
If you have read AppFuse QuickStart and chosen your stack as Spring MVC you will end up with the following command line to generate your stack.

mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=3.0.1-SNAPSHOT -DgroupId=com.mycompany -DartifactId=myproject -DarchetypeRepository=

Go ahead and paste them into you chosen working (workspace) folder in the command line window.
It will goes on generating about sometimes and mostly downloading the required java libraries.
Once done, depending your choice of "ArtifactId" a folder with that name will be created. In this case, "myproject".

[INFO] project created from Archetype in dir: /Users/hamid/Documents/workspace/myproject
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.162s
[INFO] Finished at: Fri Jun 13 08:54:43 MYT 2014
[INFO] Final Memory: 18M/228M
[INFO] ------------------------------------------------------------------------

Step 2: Generate Full Source (Service Layer modules - models, daos, managers, tests) of your stack
I like my stack as verbose as possible especially when it comes to service layer and AppFuse has plugin called appfuse to do as such. Now that you have generated your stack, navigate to "myproject" folder in your command line tool and executed the following command:

mvn appfuse:full-source

During this process you will see the following output to confirm that your service layer is being generated...

[INFO] --- appfuse-maven-plugin:3.0.0:full-source (default-cli) @ myproject ---
[INFO] [AppFuse] Installing source from data-common module...
[INFO] [AppFuse] Installing source from hibernate module...
[INFO] [AppFuse] Installing source from service module...
[INFO] [AppFuse] Source successfully exported, modifying pom.xml...
[INFO] [AppFuse] Adding dependencies from root module...

Step 3: Import into Eclipse IDE
Importing into Eclipse is easy, go ahead startup your eclipse IDE.
Now that your IDE is ready, click on File -> Import -> Maven -> Existing Maven Projects -> [Browse to your project folder with Browse button] -> Finish

Yep I know, the are some errors, we will get to that in the next steps.

Step 4: Quick and dirty way clearing off the errors in Eclipse IDE
 I have identified few errors in the imported maven projects and let clear them one by one:

1. JavaScript Source error - Exclude them!
Navigate to "Include Path"  from your project.
Right Click on your project root myproject -> Properties -> JavaScript -> Include Path.
Then under "Source" tab,  select "Excluded:" and then click "Edit" button.
Add "src/main/webapp/scripts" folder in the "Exclusion Pattern" using Add -> Browse button.

2. Replace the "ne" to != in src/main/webapp/decorators/default.jsp file

3. pom.xml error
Enclose <plugins>..</plugins> node with <pluginManagement> element, like the following:


4. sample-data.xsd error
Open the same file of src/rest/resources/sample-data.xsd in your favorite text editor (mine is textmate),
select all, copy and paste them in the same file in your IDE.

Rebuild your project with Project -> Clean or if you have the "Build Automatically" selected, your project should been instantenously re-built and the errors should have been gone.

Step 5: First run of your stack
Now that the errors have disappeared, it is time to maiden run of your stack.
before that, just make sure your MySQL 5.x Server is installed and running
In the command line window execute the following:

mvn jetty:run

for, the eager beavers who don't want to wait for all tests to be completed, you may run with skipped test as the following:

mvn -Dmaven.test.skip=true jetty:run

Next : Continue on your development...
Extends the stack with exciting frameworks such as Spring Security ACL for fine-grained access to your web resources or whatever your have in mind.

That's it! I hope you have had a perfect run of your first stack and until next time...

No comments:

Post a Comment