Earlier i showed and talked about how a badly designed web project looks like with its potential problems. Going forward, i am going to fix all that by starting from scratch.
Lets start with the most important step, defining the project file structure. Keep in mind that, there shouldn't be any duplicate jars and circular dependency, also it should be easy to manage. That's where Maven comes in. Maven makes your life so much easier that its not even funny (how i used to go by before i don't even wanna remember) because it takes care of downloading binaries (jar with source and javadocs) for almost all popular java libraries and tools like spring, hibernate, log4j, apache-commons etc. these are just to name a few.
Now, if you remember, last time we created the project using maven but it was a little tedious to create all those directories and poms by hand. This time lets make them automatically shall we ^_~
Below steps are modified version of Multiple Module Projects . Can also see Multi-module projects with WTP
c:\projects>mvn archetype:create -DgroupId=com.nyayapati.bookstore -DartifactId=nyayapati-bookstore -Dversion=0.0.1-SNAPSHOT
<packaging>pom</packaging><!-- change from jar to pom -->
c:\projects>cd nyayapati-bookstore >mvn archetype:create -DgroupId=com.nyayapati.bookstore.beans -DartifactId=bookstore-beans -Dversion=0.0.1-SNAPSHOT >mvn archetype:create -DgroupId=com.nyayapati.bookstore.core -DartifactId=bookstore-core -Dversion=0.0.1-SNAPSHOT >mvn archetype:create -DgroupId=com.nyayapati.bookstore.mysql -DartifactId=bookstore-mysql -Dversion=0.0.1-SNAPSHOT >mvn archetype:create -DgroupId=com.nyayapati.bookstore.web -DartifactId=bookstore-web -Dversion=0.0.1-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp >mvn archetype:create -DgroupId=com.nyayapati.bookstore.ws -DartifactId=bookstore-ws -Dversion=0.0.1-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp
<dependency>
<groupId>com.nyayapati.bookstore.core</groupId>
<artifactId>bookstore-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.nyayapati.bookstore.beans</groupId>
<artifactId>bookstore-beans</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>compile</scope>
</dependency>c:\projects\nyayapati-bookstore>mvn install eclipse:eclipse
One final step is to implement a source control like subversion. And add all files inside c:\projects\nyayapati-bookstore except the following (can be done by adding them in svnIgnore)
.classpath .project .settings target
That's it!! your starting project structure is complete.