Archive

Archive for the ‘Maven’ Category

How to unit test Hibernate DAO’s with H2 and Spring

May 12, 2014 Comments off

Source can be downloaded from link;

Writing Unit test cases are very common these days.We can write a Unit test for the functionality with Mocking.I personally feel we should not do Mocking while testing DAO.I prefer to write test cases for the DAO’s by pointing to the Database itself.Here the problem is we cannot execute tests on the production or development database since it will spoil the existing data, because we can build the same project any number of time, especially when we configure continues integration.

In memory databases or file based database comes in handy in this particular situation.There are lot many databases available of this kind like h2, HSQLDB e.t.c.

Here below i have extended a sample created in the below post and have written unit test with h2 database.

Link : http://examples.javacodegeeks.com/enterprise-java/spring/jpaorm/spring-hibernate-mysql-and-maven-showcase/

Project Structure

Image

 

Create a test class with the similar package structure as source class in src/test/java

Image

Sample Insert.sql below.

Image

Sample delete.sql below

Image

Now the main part come into the picture.applicationcontext.xml

We need to configure the h2 database data source as per below.

Image

and the Session Factory as per below.

Image

and we have to add spring-test dependency to the pom file.

Image

Categories: H2, Hibernate, Java, Maven, Spring Tags:

Maven SkipTests command

May 29, 2011 Comments off
Categories: Maven

Running Maven jetty plugin with a different port

May 29, 2011 Comments off
Categories: Maven

how do I set eclipse.ini -vm option for m2Eclipse ?

May 24, 2011 Comments off

I installed maven plugin for eclipse, then I get an error like below:

please make sure the -vm option in eclipse.ini is pointing to a JDK

how to use -vm option to point to my jdk in eclipse.ini?

Solution:

add jdk javaw.exe file path as the first line to the eclipse.ini file and restart the eclipse.

-vm
C:/Program Files/Java/jdk1.6.0_24/bin/javaw.exe

Categories: Maven

Maven Exception

March 23, 2011 Comments off

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.4:shade (default) on project sag-server: Error creating shaded jar: Invalid signature file digest for Manifest main attributes -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.4:shade (default) on project testProject: Error creating shaded jar: Invalid signature file digest for Manifest main attributes
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: Invalid signature file digest for Manifest main attributes
at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:503)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
… 19 more
Caused by: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:221)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:276)
at java.util.jar.JarVerifier.update(JarVerifier.java:188)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:325)
at java.util.jar.JarFile.getInputStream(JarFile.java:390)
at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:94)
at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:444)
… 21 more

Solution:

Step 1:go to pom.xml file

step 2:goto shade plugin part and add the below given lines

<filters>
<filter>
<artifact>*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.INF</exclude>
</excludes>
</filter>
</filters>
[/sourcecode=”xml”]

Categories: Maven

Debugging maven web application with eclipse

March 3, 2011 Comments off

>

Recently I started a new JEE project using Maven2 as build tool, choice done du to the different services that it offers for project with a lot of modules and complex dependency ….
One of the problems that I faced is debugging web layer with respect to the directory structure of the default web archtype.

Here is the best method I found to solve this need:

I suppose that you already created a maven2 web project if not see :
http://maven.apache.org/guides/mini/guide-webapp.html

To run http web server I use jetty plugin by simply adding the jetty plugin to the pom.xml
http://jetty.mortbay.org/maven-plugin/howto.html

In order to validate this phase it’s possible de run the web app from the command line: mvn jetty:run and wating for maven to download the plugin and if successful running the application.

After that It’s time to configure eclipse for debugging the web app by selecting the Run > Debug … from the menu
# Set Main Class to “org.codehaus.classworlds.Launcher”

Go to the argument tab:
# Set Program arguments to “jetty6:run”
# Set VM arguments to “-Xmx512M -Dclassworlds.conf=[MAVEN_HOME]/bin/m2.conf -Dmaven.home=[MAVEN_HOME]”
(Replace MAVEN_HOME with the location of maven on your system)

Go to the classpath tab:
# remove the application from the user entries
# add the “[MAVEN_HOME]/core/boot/classworlds-1.1.jar” to the user entries

Go to the source tab:
# add the current project to debug

Now you can start debugging your application like you do it always

It is very interesting to set the –o option to the maven command in order to accelerate the fix/debug process.

Reference:
http://mahertb.blogspot.com/2006/08/debugging-maven-web-application-with.html

Categories: Maven
%d bloggers like this: