Saturday, 20 December 2014

How to skip test case in Maven build ?

You can skip the test in two following ways :-

By configuring the Pom.xml , if you are using surefire plugin then you can configure as below. 


<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>

  </build>

For specific module test you can create profile in pom.xml for specific environment and it will help to skip the test cases.You can skip this specified profile "noTest".


<profiles>
    <profile>
      <id>noTest</id>
      <activation>
        <property>
          <name>noTest</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>


By using Command Line :- 


1) -Dmaven.test.skip=true

2) -DskipTests ( The values can be true/false) 

Example - 


1 ) mvn clean install -DskipTests=true

2 ) mvn clean install -Dmaven.test.skip=true

 

Hope it will help you.

Follow for more details on Google+ and @Facebook!!!


Find More Solutions -

How to create maven job in Jenkins



As we know Jenkins is a tool  , and its used for build and release any project.There are many such tools are available i.e. Hudson.  For creating job/project on Jenkins below steps/screen shots need to follow.

Step 1 - Login & Dashboard

Login to Jenkins with valid credential and you are in Dashboard.



Step 2 - Create Job

Click New Item (left side menu) to create a new Job/Project . Provide the Job Name as per your project requirement. Here this example my job name is "HelloWorld_Job".




Here in the above image many options are available for creating many kind of job. Also you can copy any existing job instead of creating a new. You can select Copy Existing Items and provide the existing job name inside the text box.



Step 3 - Job Configuration


There are few certain configuration is required for this job execution. For building any job we need few configuration and commands as below.





You need to configure the source code location from which you are going to build.In the below image I have used "Git" as source code management tool. You can use any source code management tool like SVN, CVS ,etc. And the important part of this configuration is the location of your project . So, make your the location you have provided is correct and relevant.



Then  there are few more setup is required make this job elegant and accurate. But these options/settings are fully optional. Read all the settings carefully and configure as per you needs.Some useful configurations as below.




As the part of configuration the major part is maven command for execute the build. The screen shot below shows the configuration about maven command for goal. This project is a maven project and we need maven command for build this job/project. 




Common maven commands which is used for a clean build is "mvn clean install". Also there are many other additional commands which will help you to achieve your goal.Read more here about Maven.


Step 4 - Start Build 


The final step is to start the build. Once all the above steps are completed and you are ensure about the configuration , then you can do the build . The build execution will provide you the artifacts i.e. jar ,war,ear, etc.




 If the job execution is success, the you can go for deployment. Now you are done with this job...


Enjoy the Build and Release process.






Hope it will help you. Happy Building.

Follow for more details on Google+ and @Facebook!!!


Find More Solutions -

Wednesday, 17 December 2014

Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref



This issue occurs when I tried with Jenkins build using Maven Release Plugin. I was trying to build my production release artifacts. I was building my "master" branch and its for final release. I have used Git as repository. I faced this issue when clicked on "maven release build" link on left side corner of my Maven project (Jenkins job) .


As we know build issue is common for developers those are actively participating with Build and Release. This issue over Jenkins is common , but I never found any direct or easy solution for this. I spend couple of hour to resolve and goooogle almost all relavant sites and article.But, not able to work out. Finally did it by some HIT and TRY ,then it works for me.   


Issue log details :-

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.884s
[INFO] Finished at: Wed Dec 17 18:05:43 EST 2014
[INFO] Final Memory: 15M/301M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project hello_world_app: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[JENKINS] Archiving /opt/jenkins_dev/workspace/SDP_BIZ_HELLO_WORLD_APP/pom.xml to in.com.company.xcop.sdp.bizservice.test.dao/hello_world_app/0.0.8-SNAPSHOT/ hello_world_app -0.0.8-SNAPSHOT.pom
channel stopped
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds



Solution :-

 In Jenkins job , open the configuration and go to Git configuration => Advance Options => << add your local branch name >>. In my case I have added "master" .

If you are using some other version of jerkins then , you may find the similar settings with other way. In the same way Git configuration => Advance Options => Additional Behaviors => Check out to specific local branch => << Add your local branch name >>.   

Attached the screenshot below with highlight. 







Hope it will help you. Happy Building.

Saturday, 29 November 2014

SEVERE: Catalina.start: org.apache.catalina.LifecycleException: Failed to start component

Issue : Catalina.start: org.apache.catalina.LifecycleException: Failed to start component


The issue I faced with Tomcat7 during starting the server. Usually we start server from Eclipse server configuration during the development process. The server not able to start and not ready to give the service , it was trying to run for few secs but failed with window alert.


Console logs :-   


Nov 29, 2014 7:16:46 PM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start:
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:675)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1136)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more

Caused By - There may be many reason , but I found mismatching of JRE versions. This is likely a JVM class loader issue. If you have multiple JAR files in the same directory with the same class in them , there is no defined order in which the JAR files will be searched. My installed JVM was version JDK 6 but my tomcat configuration was JDK 7.Check your server runtime configuration on Eclipse for JDK version. 



Also I did the cleanup for the server setting in Eclipse.For cleanup , right click on server configuration and click on clean.Now it works for me.Hope it will help you.





Enjoy..........Happy Deployment.


Friday, 24 October 2014

Top 5 Oracle Service Bus fundamental Questions



Top 5 Oracle Service Bus fundamental Questions.

Q1. What is OSB and why we need OSB?
Ans – In simple answer it’s a middleware tool provided by Oracle. It stands for Oracle Service Bus. It is used to delivers low-cost, standards-based integration for mission critical SOA environments where extreme performance and scalability are requirements. It simply transforms any complex architecture to simple by connecting different application and service.  

Q2. What is Proxy Service?
Ans - Proxy service is a service which you can exposed to the outside world. Instead of publishing the actual service to real world we can publish the proxy service with additional / optimized business logic. Proxy service can call any other proxy service (ps), local proxy service (lps) and business service (bs). It often called over http protocol.

Q3. What is Business Service?
Ans – Business service is nothing but it defines the WSDL. As a standard business service never called from outside world. It’s always called by proxy service. It directly communicates with the business.

Q4. What is Local Proxy Service?
Ans – Local proxy service is treated as internal service. It’s not exposed to outside world. It’s normally used for internal validation and it’s always used internal between proxy service, local proxy and business services. It always called over “local” protocol. They do not have an endpoint which a consumer sitting outside the OSB can invoke. In order to invoke a internal proxy service the consumer will have to invoke an external proxy service which in turn will have to route it to the internal service.

Q5. What is VETO pattern?
Ans – VETO stands for Validation, Enrich, Transform and Operate. All logic in ESB / OSB should be followed by VETO pattern. The "Validate" step is usually the first part of any ESB process. Since validations are normally done in business services thus this step is not required in ESB. Moreover validations are expensive operation in ESB. The "Enrich" step involves adding additional data to a message to make it more meaningful and useful to a target service or application. The "Transform" step converts the message to a target format. The "Operate" step is the invocation of the target service or an interaction with the target application.

Saturday, 11 October 2014

IBM Java Interview Questions for 3-8 Year Experience.

Experienced Java Interview Questions Asked By IBM - 3-8 Year 


Q. What is Difference between interface and abstract class?


Ans : Interface and Abstract class both are looks similar from declaration point of view. The major difference is for implementing multiple inheritance you need interface, because java does not support multiple inheritance. All methods and  variables of interface are public. Interface can contain only abstract method (without method body)   , but abstract class can contains abstract and non-abstract methods. Abstract class must be inherited by sub class. These are few major points you can answer for interview. For more in interface read here.



Q. Can you write final method  in interface?


Ans : No , because interface methods do not have body . It need to be implement in implemented class.



Q. Is this possible to write final method  in abstract class?


Ans :  Yes, you can do this by using non abstract methods.



Q. What is Difference between Iterator and  ListIterator?


Ans : Both are used to retrieve the data from collection. Iterator only traverse in forward direction, but ListIterator can traverse in both forward and backward direction. ListIterator has hasPrevious() and previous() method which is not available in Iterator.

Q. Difference between synchronized  block and synchronized method ?


Ans : Synchronized Method defines a self contained block and  its easy to handle in multi-threaded environment. Both act as similar; there is no major advantage over each other. The difference is that a synchronized block can choose which object it synchronizes on. A synchronized method can only use 'this' (or the corresponding Class instance for a synchronized class method).



Q. Difference between String and StringBuffer class ?


Ans :  String is immutable, but StringBuffer is not. StringBuffer used to represent characters that can be modified.  StringBuffer is faster when performing concatenations. This is because when you concatenate a String, you are creating a new object (internally) every time since String is immutable.


Q. How to get the session object in jsp?


Ans : By using implicit object “session”. You can use session.getAttributes() methods.



Q. How to get the session factory object in hibernate?


Ans : By the use of buildSessionFactory() method  .Syntax as below.



  SessionFactory factory= new Configuration().configure().buildSessionFactory();

Q. How to handle the runtime exception in jsp?


Ans : In jsp page directive you can use isErrorPage=true.



Q. Difference between method overloading and overriding?


Ans  :  Both are concept of polymorphism. Method overloading is a form of static binding. Method overriding is a form dynamic binding. Overloading is applied in single class, but overriding is applicable for inherited class. Method overloading is always specific to method signature. It defines number of parameter, type of parameter and sequence of parameter.



Q. Difference between java.util.date and java.sql.date ?


Ans : As we know every database support most three form of entry i.e. date, time and  timestamp. In java JDBC having all those supports using java.sql.Date, java.sql.Time, java.sql.TimeStamp. Internally all these JDBC classes extends java.util.Date.



Q. I have 1 to 100 elements in array unordered, one element missed find that one?


Ans : There is existing old formula. Calculate the sum of all numbers stored in the array of size 11 means it hold 12 data. Then, subtract the sum from (12 * 13)/2

Basic Formula: n * (n + 1) / 2. 

Q. Difference between equals() and hashcode()?


Ans : Both methods are from Object class. Equals() method is used to compare the contents of object or reference. But, hashcode() method is used to get the unique hash code for any object. Hashcode is used for hash implementations like HashMap, HashTable, HashSet etc.



Q. What is Comparator?


Ans : It’s an interface. It has 2 important methods. But, the frequently used method is compareTo() . It compares 2 different objects.



Q. We have equals() to compare two methods then why comparator again ?


Ans : Because , equals() method will only compare the content . It cannot compare two different objects. Comparator interface has compareTo()  method  which compare 2 different object.



Q. What is autowiring in spring ?


Ans : Autowiring is a mechanism for injecting objects in Spring. By using the annotation @Autowired , you can achieve that.

Its available inside  org.springframework.beans.factory.annotation package.





Q. We can get the container object through Bean factory and Application context what is the difference in both?


Ans : A BeanFactoryis used to just instantiates and configures beans. An ApplicationContextalso does that, andit provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP. Read more on Spring Specification.



Q. What is the Difference between get() and load() in hibernate ?


Ans : These two methods are most useful method in Hibernate. Both method s are used to get/fetch the records from database. The  get() method will return null , if the data not found. The load() method always returns proxy.   



Q. Difference between page and page context in jsp ?


Ans : As we know both are implicit object of JSP. Page is a type java.lang.Object and it’s an instance of generated servlet from “this” JSP, but PageContext is a type of javax.servlet.jsp.PageContext. PageContext is used for storing and retrieving page-related information and sharing objects within the same translation unit and same request.



Q. What is application in jsp ?


Ans : It’s a scope. It defines the visibility for data over Application.