Maven + CRUD + Spring + Hibernate + MySQL/Sql Server 2008

来源:互联网 发布:手机热血传奇挂机软件 编辑:程序博客网 时间:2024/05/21 19:39

Tips:

Create a dynamic web project; To replace the default src folder to src\java\main and src\java\test; then change to maven project;

Although rarely, but sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don't exist in any public repository like Maven Central. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar

Entity-->Dao(interface and imp)-->Service(interface and imp)-->Controller-->Jsp

 

Open a command prompt, go to your project directory and run: mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
The eclipse:eclipse portion will regenerate your project files etc, the last 2 properties are more for convenience but I like downloading the sources and javadoc.

 

After a failed attempt, maven will leave a small file in your local .m2 repository that will prevent any attempt to re-download the file unless the update interval has elapsed or you force the updates using the maven-U switch described in other answers.

Just delete the folder for that artifact in your local m2 repository and update you project; a new download attempt will trigger.

rm -rf ~/.m2/repository/com/caucho/hessian/3.1.5

 

 

1) Create a maven project

mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=Log4jTestProject
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=falseRun above command in your eclipse workspace or any other IDE you are working in. If you already have a project in your workspace, then directly go to step 3.

2) Convert the project to eclipse supported java project

mvn eclipse:eclipseAbove command will convert maven project to eclipse java project. Now, import the project to eclipse.

3) Update pom.xml file with log4j dependencies Add below given dependencies to pom.xml. view sourceprint?

<dependency>
<groupid>log4j</groupid>
<artifactid>log4j</artifactid>
<version>1.2.17</version>
</dependency>Run below command to download required jars in your local system and update project runtime dependencies also.

mvn eclipse:eclipse

4) Test the application with BasicConfigurator

package com.howtodoinjava; 


03.import org.apache.log4j.BasicConfigurator;
04.import org.apache.log4j.Logger;
05.

06.public class Log4jHelloWorld {
07.

08.
static final Logger logger = Logger.getLogger(Log4jHelloWorld.class);
09.

10.
public static void main(String[] args)
11.
{
12.
//Configure logger
13.
BasicConfigurator.configure();
14.
logger.debug("Hello World!");
15.
}
16.}Output:

0 [main] DEBUG com.howtodoinjava.Log4jHelloWorld - Hello World!