Posts

Build Maven Multi Module Project and Run using one Command

When we have maven multi module project, there will be dependency between sub project. Therefor if you need to build all projects need tp navigate to parent directory and run the mvn clean install command.

If we have web based multi module project, currently most people doing is go to parent directory and build the all projects using mvn install or mvn clean install command, after that navigate to web project and start web container.

Ex: Projects are P1(parent project), Core and Web. When we building project go to P1 and build the all subprojects, after that go to web project and start jetty server using mvn jetty:run

But that approach wasting you time little bit and when we doing same thing all the time it will become boring  task to do(build parent and go to child folder and run the server)

For avoid this issue I am going to show how to run web project with out navigate to child project.

following command will help you to run specific project without moving to sub project folder.

mv…

Change Jetty Server Running Port

Jetty is one one of the best development server which I have ever used. It is easy to work with jetty server and its light weight

Here I am going to show how to change jetty server running port.  Jetty server default running port is 8080.

Port with Maven: 

 Command line:          For starting jetty server we are using mvn jetty:run command. We can change the port jetty server running by passing run time argument to it.

mvn -Djetty.port=80 jetty:run


 Using pom.xml
                By changing jetty plugin system properties as below, you can change the jetty running port.
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <configuration> <stopPort>9966</stopPort> <stopKey>foo</stopKey> <systemProperties> <systemproperty> <name>jetty.port</name> <value>80</value> </systemproperty> </systemP…

Maven add jar without install

I have some problem with adding external jar in to maven project without install it. If I install JAR file other people who working on same project, have to install same JAR. them I want to avoid that issue.

First need to place jar file inside lib folder. After that using following POM entry we can use it as dependency.

<dependency> <groupId>com.chandana</groupId> <artifactId>example</artifactId> <version>0.1</version> <scope>system</scope> <systemPath>${basedir}/lib/example.0.1.jar</systemPath> </dependency>

Ex: <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.5.0</version> <scope>system</scope> <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath> </dependency>
 Here very important option is <scope>system</scope>. It's say dependency provide with system, no need …

Maven commands and hint

svn checkout without subfolders

svn co --depth immediates URL
maven without internet(Without downloading)

mvn -o install
mvn --offline install

Force the check of the latest dependency jars
mvn -U install
mvn --update-snapshots install

*** -U option to update your snapshots

Skip the tests

mvn install -DskipTests

also use the maven.test.skip property to skip compiling the tests

mvn install -Dmaven.test.skip=true

Remote Debug

mvnDebug test
mvnDebug install


To avoid OutOfMemoryError

To avoid OutOfMemoryError when running maven, set environment variable MAVEN_OPTS as below

MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=256m


If you have issue with Maven does not find JUnit test cases to run:
By default Maven runs tests class which names start with Test or end with Test or TestCase.Do not messed up the naming convention

Introduction to OSGi - 2 (OSGi Services)

There are so many OSGi tutorials, blogs, and samples. I am going to add another OSGi sample/tutorial with my OSGi leanings. Here is my previous article regarding OSGi(Introduction to OSGi).

An OSGi Service is a java object instance which is registered with OSGi framework with set of attributes. Services can be accessed via service registry(performed via the class BundleContext). BundleActivator is to be invoked on start and stop. When BundleActivator call start method we are going to register our service. After that any bundle can access that service.

Service Bundle:

In service bundle you need to export your service and need to register it via service registry. When we are exporting service we export interface package only. As usual that is to hide the implementation from the other bundles.

I have created a sample OSGi project called HelloServcie

MANIFEST.MF
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: HelloService Bundle-SymbolicName: com.chandana.hello.HelloSer…

How to Ignore Files or Directories in Subversion

Image
We are facing a common problem when trying to commit some changes to the SVN. That is each time we have to ignore some JAR files, because those JAR files are user run time specific and if they are committed, it would not work on other local runtimes.

Here is a pretty simple solution for this problem. We can tell subversion to ignore directories or specific files as follows.

Ignore directories or specific files.
   svn propedit svn:ignore ./some_path
It will ignore all files in the specified directory. Here only wildcard indication is supported, and regular expressions are not supported.

Example wildcard supprt:
 svn propedit svn:ignore *
Example ingnore class files with wildcard:
  svn propedit svn:ignore *.class

If you are using Eclipse SubEclispe plugin,

Right Click file or folder --> Team --> Then click on svn:ignore

How to debug using Maven Jetty

Image
Debugging is a better approach to find out bugs in our programs. Here is a way to debug a maven project, and I am going to run my web application in the Jetty server.

First you need to add the following environmental variables on your Windows/Linux environment.

MAVEN_OPTS = -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y Now go to your maven web project location through command line and start the jetter server -> mvn jetty:run



Now in eclipse debug configuration, add a remote Java application instance on port 4000. Then Add some debug points to your codes  and start the remote app instance on debug mode. You can see the steps from following screen shots.





In this manner you can debug your java web apps and find out the bugs. With this way you can debug your java web app.

if you are using maven latest version( Maven 2.0.8 or later)

run the
mvnDebug command instead of
mvn and attach a debugger on port 8000.

Love to hear from yo…