December 29th, 2010
Vinay
So you have a jar file which you would like to add in maven and not sure what the definition would be . Here is what you do
1. Go to http://mvnrepository.com/
2. Search for file you want to add for eg c3p0
3. You might see couple of results matching your search.
4. Find the definition that matches your need for eg in this case
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1</version>
</dependency>
December 29th, 2010
Vinay
Let us say you want to configure c3p0 connection pool in your application through maven.
Here is the definition you need to add in pom.xml
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1</version>
</dependency>
If you would like to see how to configure c3po connection pool in Spring see this post Using connection pool with MYSQL in Spring applicationContext.xml
December 29th, 2010
Vinay
In the last post , we had talked about SOAP being retired in favor of REST based service. in which we discussed advantages of REST over SOAP.
This post will be a short tutorial on creating your first REST based service.
What is REST and how are they accesses ?
From Sun(oracle) docs
RESTful web services are built to work best on the Web. Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enable services to work best on the Web. In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs), typically links on the Web. The resources are acted upon by using a set of simple, well-defined operations. The REST architectural style constrains an architecture to a client/server architecture and is designed to use a stateless communication protocol, typically HTTP. In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.
Why use JERSEY ?
Java defines standard REST support via JAX-RS (The Java API for RESTful Web Services) in JSR 311. Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services
Here is the objective of our tutorial
- Set up development environment and infrastructure to build first REST full app using JERSEY
- Create the sample application
- Deploy and run in tomcat Read more…
December 28th, 2010
Vinay
In windows environment , open up your startup.bat and add to file somewhere in beginning
rem set remote debugger
set JPDA_ADDRESS=8001
set JPDA_TRANSPORT=dt_socket
echo Remote debugging started
Add this to end of your startup.sh file
call “%EXECUTABLE%” jpda start %CMD_LINE_ARGS%
Make sure you comment out
call “%EXECUTABLE%” start %CMD_LINE_ARGS%
When you are connecting with eclipse, set your debug port at 8001
Now when you start your server , you would see the message Remote debugging started
December 26th, 2010
Vinay
We had talked about PRINCE2 in our earlier posts.
What is PRINCE2
Understanding PRINCE2 Certification exam
Difference bewteen PMP and PRINCE2 certification
Ikoko has created PRINCE2 Foundation Exam practice test for our readers. This is a mock of PRINCE2 2009 Foundation exam and consists of 50 questions.
Looking forward for your feedback and comments.
December 24th, 2010
Vinay
In the last post, I had talked about Building an executable jar with Maven
The same can also be achieved using Shade plugin. Below are the changes you will do to build an executable jar with Maven’s shade plugin.
If you are using a shade plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=”org.apache.maven.plugins.shade.resource.ManifestResourceTransformer”>
<mainClass>com.your.executable.class.name</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Then you might see some warnings like
[WARNING] We have a duplicate net/sf/cglib/util/StringSwitcher$StringSwitcherKey.class in C:\dev\repository\cglib\cglib-full\2.0.2\cglib-full-2.0.2.jar
What is fix for this ?
Use assembly plugin as described in here. Building executable jar with maven
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=”org.apache.maven.plugins.shade.resource.ManifestResourceTransformer”>
<mainClass>com.fmcna.cmd.digicomm.DigicommController</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
December 23rd, 2010
Vinay
This is one of the most commonly asked questions on Maven.
How to build executable jar with maven.
The idea is to build a jar with all its dependencies so that you can execute java – <nameof jarfile.jar>
Here is how to do it in maven. Add this to your pom.xml
<build>
<plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fully.qualified.nameOfCLass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
You can run mvn assembly:assembly and a jar file with all the dependencies will be built.
This is good if this is a standalone project. But if you have a parent pom and there is sub project which needs an executable jar, use goal single to build it along with the rest of the application.
Here is the pom.xml for this
Read more…
December 23rd, 2010
Vinay
In this post , I will talk about how to set up connection pool through Spring’s applicationContext.xml for mysql and hssql.
We were using in memory database HSSQL db in our application for doing testing and we discovered that we required more than one connection. So basically we need to set up a connection pool.
The old definition looked like
<bean id=”dataSource” class=”org.springframework.jdbc.datasource.DriverManagerDataSource” >
<property name=”driverClassName” value=”org.hsqldb.jdbcDriver”/>
<property name=”url” value=”jdbc:hsqldb:file:testdb;shutdown=true”/>
<property name=”username” value=”sa”/>
<property name=”password” value=”"/>
</bean>
Before talking about how we set up a connection, let us talk about some basic concept. All databases support connection pooling , even in memory database like hssql. For setting up a connection pool through Spring’s application Context, you should be using the class which support the pooling
Notice here that we are using class=”org.springframework.jdbc.datasource.DriverManagerDataSource”.
This class does not support connection pool .
So if you try to add properties such as minPoolSize and maxPoolSize , spring will throw exception similar to
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in file
Read more…