Wednesday, 2 September 2015

Why You Should Move to Rails 5

Every one of us is waiting for a new and clean release of Rails 5 , which not only accepts the SPA(Single Page Application) Implementation easily but also has enhanced the performance and structure of thr most popular Rails frame work.

The release of Rails 5 is supposed to be fall on summer/fall of 2015.

Lets discuss the rich changes/implementation of Rails 5.

MERGING RAILS API

SPA is on rise, while developing a Single page application we rails developers faced a lot of issues, the routing was lacked and there were several security vulnerabilities that we had to handle.

In Rails 5, the rails-api Gem will be merged into core allowing the use of Rails as Simple JSON API. Which ease building API using Javascript Library.

NO MORE RAKE COMMANDS

In Rails 5 all the current rake commands will be accessible via the rails command.
When you want to run a migration, you will type rake db:migrate in Rails 4. In Rails 5 this will become railsdb:migrate.
The reason for this change is that currently it's not very logical which command has to go through rake and which command should go through rails. When you're working with rails for a longer time it becomes second nature, but only because you remember it.
For a newcomer, this is a big problem and makes learning rails confusing.
See this issue on GitHub for more details .

WHEN TO USE RAKE

You can now restart all of your apps with the command rake restart.
See this Pull Request for more details .

TEST CASES CHANGES

In Rails 5, the test helpers assigns() and assert_template() will be deprecated. Its because testing instance variable and what template is being called smells bad. These are internals of controller and controller tests should not care about what vars I set.
Controllers test are concerned about HTTP,Cookies, Renders, Redirects and so on.
More Details can be found here .

BLOOMING RUBY 2.2.1

Rails will only support Ruby 2.2.1 and up. Since it wants to be able to leverage all the speed improvements in the newer ruby versions. They skipped version 2.2.0 since it has a segfault bug source.

TURBOLINKS 3

For the folks who don’t like to meddle around with JS, Turbolinks offers an instantaneous performance boost, and allows you to retain most of your page and selectively update certain regions through partials. This is very similar to how SPA’s work, and you can choose to do all this from the server.

ACTION CABLE

Many projects these days use WebSockets to push live updates to the client. While most client browsers(IE > 9, Chrome, Firefox, Safari) have started to support this, we still need a robust client on the server to manage the subscribers and send an update signal appropriately. This feature is available out of the box in some of the newer frameworks, like Phoenix for Erlang. However, the Rails community had to resort to third party implementations, like Pushr, to get this working.

Rails traditionally offers all the tools that one needs to build a great app out of the box. That’s one reason why it is so popular, especially among the startup community. The lack of WebSocket support was a reason for major discontent among the community. It looks like the Rails core team took note of this and came up with Action Cable.

As a Team of Ruby , Rails, Java,JS and CSS Developer we are Commited towards the trending technologies and simplifying developers and Clients Projects .

For any Information regarding Upgrading your Rails Application or building your ideas we welcome you to Our Community.

This post is created by Santosh Mohanty . You can contact him for any questions at santa.jyp@gmail.com or message him on his linkedIn profile .


How To Create Rest WebServices With GUICE And Jersey

This is a simple example of how to use Google Guice , with Jersey to create JAX-RS web services , which can be deployed to any servlet container like Tomcat , Jboss , GlassFish etc .


We will be creating a simple Transaction Service , which will Create , update , and query Transactions . For this example , we are not using any database but a simple hashmap to store it .


So , first of all lets have a look at our maven pom.xml file . I have added dependency for Guice(jersey-guice) which is a guice extension of jersey.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.javaroots</groupId>
 <artifactId>codeChallenge</artifactId>
 <version>1.0</version>
 <packaging>war</packaging>
 <name>Code Challenge</name>
 <description>Code Challenge Sample Prject</description>

 <dependencies>
  <dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-guice</artifactId>
   <version>1.19</version>
  </dependency>
  <dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-json</artifactId>
   <version>1.19</version>
  </dependency>

  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>3.1.0</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.17</version>
  </dependency>
  <dependency>
   <groupId>org.mockito</groupId>
   <artifactId>mockito-all</artifactId>
   <version>1.9.5</version>
  </dependency>

  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.1</version>
  </dependency>

 </dependencies>
 <build>
  <finalName>${artifactId}</finalName>
 </build>

</project>

Now we have DAO like this .
package com.javaroots.dao;

import java.util.List;

import com.javaroots.model.Transaction;

public interface TransferDAO {
 
 public void create(Transaction tr);
 public Transaction get(Long id) ;
 
}
package com.javaroots.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.google.inject.Singleton;
import com.javaroots.dao.TransferDAO;
import com.javaroots.model.Transaction;
@Singleton
public class TransferDAOMemoryImpl implements TransferDAO{

 private ReadWriteLock lock ;
 private Lock readLock ;
 private Lock writeLock ;
 private Map store ;
 
 public TransferDAOMemoryImpl()
 {
  lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
  store = new HashMap();
 }
 
 public void create(Transaction t){
  if(t.getParent_id() !=null)
  {
   Transaction parent = get(t.getParent_id());
   if(parent == null)
    throw new RuntimeException(" Invalid parent id . id not exist in system");
  }
  writeLock.lock();
  try
  {
   store.put(t.getId(),t);
  }
  finally
  {
   writeLock.unlock();
  }
 }
 
 public Transaction get(Long id) {
  readLock.lock();
  try
  {
   return store.get(id);
  }
  finally
  {
   readLock.unlock();
  }
 }
}

Model Class :
package com.javaroots.model;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown=true)
public class Transaction {
 
 private Long id ;
 private Long parent_id ;
 private String type ;
 private Double amount ;
 
 public Transaction(){};
 
 public Transaction(Transaction t)
 {
  this.id = t.id ;
  this.parent_id = t.parent_id;
  this.type = t.type ;
  this.amount = t.amount ;
 }
 @JsonIgnore
 public Long getId() {
  return id;
 }
 @JsonIgnore
 public void setId(Long id) {
  this.id = id;
 }
 
 public Long getParent_id() {
  return parent_id;
 }

 public void setParent_id(Long parent_id) {
  this.parent_id = parent_id;
 }

 public String getType() {
  return type;
 }
 public void setType(String type) {
  this.type = type;
 }
 public Double getAmount() {
  return amount;
 }
 public void setAmount(Double amount) {
  this.amount = amount;
 }
 
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((id == null) ? 0 : id.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  Transaction other = (Transaction) obj;
  if (id == null) {
   if (other.id != null)
    return false;
  } else if (!id.equals(other.id))
   return false;
  return true;
 }
 
}

Now following is our Rest Service class :
package com.javaroots.services.rest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.javaroots.dao.TransferDAO;
import com.javaroots.model.Transaction;

@Singleton
@Path("transactionservice/")
public class TransactionService {
 
 private TransferDAO transferDAO ;

 @Inject
 public TransactionService(TransferDAO transferDAO)
 {
  this.transferDAO =  transferDAO ;
 }
 
 @PUT
 @Path("transaction/{transaction_id}")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Response createTransaction(@PathParam("transaction_id")Long transactionId , Transaction entity) {
  entity.setId(transactionId);
  transferDAO.create(entity);
  Map map = new HashMap();
  map.put("status","OK");
  return Response.status(Status.OK).entity(map).build();
 }
 
 @GET
 @Path("transaction/{transaction_id}")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getByType(@PathParam("transaction_id")Long transactionId) {
  Transaction toRet = transferDAO.get(transactionId);
  return Response.status(Status.OK).entity(toRet).build();
 }
}

Now we bind this together using google Guice's ServletContextListener . To enable json support , you need to bind JacksonJsonProvider as well .
package com.javaroots.listeners;

import org.apache.log4j.Logger;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.google.inject.servlet.GuiceServletContextListener;
import com.javaroots.dao.TransferDAO;
import com.javaroots.dao.impl.TransferDAOMemoryImpl;
import com.javaroots.exception.RestExceptionMapper;
import com.javaroots.services.rest.TransactionService;
import com.sun.jersey.guice.JerseyServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;

public class AppInitilizer extends GuiceServletContextListener {

 Logger log = Logger.getLogger(AppInitilizer.class);
 @Override
 protected Injector getInjector() {
  
   return Guice.createInjector(new JerseyServletModule() {
             @Override
             protected void configureServlets() {
                 bind(TransferDAO.class).to(TransferDAOMemoryImpl.class);
                 serve("/*").with(GuiceContainer.class);
                 // Configuring Jersey via Guice:
                 bind(TransactionService.class);
                 bind(RestExceptionMapper.class);
                 bind(JacksonJsonProvider.class).in(Singleton.class);

             }
         }); 
 }
}

Now include this in web.xml .
<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 version="3.0">

 <filter>
  <filter-name>guiceFilter</filter-name>
  <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>guiceFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
  <listener>
        <listener-class>com.javaroots.listeners.AppInitilizer</listener-class>
    </listener>

</web-app>
Now you can access service at localhost:8080/{contextpath}/transactionservice

Post Comments And Suggestions !!!

Wednesday, 19 August 2015

Error In Starting of Mule App

Some times Mule app failed to start , throwing weird exception like this :
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'mule'.
        at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
        at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
        at org.mule.config.spring.MuleApplicationContext.loadBeanDefinitions(MuleApplicationContext.java:113)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
        at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89)
        at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109)
        at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:119)
        at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73)
        at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
        at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
        at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101)
        at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57)
        at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
        at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
        at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:84)
        at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:207)
        at org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64)
        at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:47)
        at org.mule.module.launcher.MuleDeploymentService.guardedDeploy(MuleDeploymentService.java:420)
        at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:186)
        at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:160)
        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.mule.module.reboot.MuleContainerWrapper.start(MuleContainerWrapper.java:56)
        at org.tanukisoftware.wrapper.WrapperManager$12.run(WrapperManager.java:2788)
[28/01/2015 18:17:07 INFO  DefaultMuleApplication:197] App 'plum-slice-rest-api-3.3.4-SNAPSHOT' never started, nothing to dispose of
ERROR 2015-01-28 18:17:07,426 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Failed to deploy app                                     +
+ 'test', see below          +
The solution which you can try in this case pretty simple .
Just delete .mule folder
Post Comments and Suggestions !!

Thursday, 6 August 2015

Double Colon Operator in Java

Java 8 has introduced double colon (::) apart from lambda expressions. Let's see how does it work .

public class DoubleColonTest {
  
  interface MyInterface{
      public void interfaceMethod(String input);
  }
  
  public static void staticmethod(String input)
  {
    System.out.println(" static mymethod  " + input);
  }
  
  public void method1(String input)
  {
    System.out.println(" mymethod  " + input);
  }
  
  public static void main(String[] args) {
    DoubleColonTest obj = new DoubleColonTest();
    MyInterface dd = obj::method1;
    dd.interfaceMethod(" test string ");
    MyInterface second = DoubleColonTest::staticmethod;
    second.interfaceMethod(" test static string ");
      
    
  }

}
In this example , we have a functional interface with method name interfaceMethod , and we have a DoubleColonTest class which has two method which takes same parameters as interfaceMethod .Now this line :
MyInterface dd = obj::method1;
This line tells the compiler to create an implementation of MyInterface by applying the body of method1 defined in the DoubleColonTest class . Since this method is instance method , we need to use instance of class. This is called instance method reference .We can take static method reference also like this :
MyInterface second = DoubleColonTest::staticmethod;
So , now we can reference methods and reuse them again and again . We can also reference Constructor also , but we need to have a constructor which matches the interface method signature like this :
public DoubleColonTest(String in)
  {
    System.out.println(" constructor  " + in);
  }
Now to create an implementation of MyInterface , just need to write :
 MyInterface third = DoubleColonTest::new;
 third.interfaceMethod(" test string ");   
please post comments and suggestions !!!

Tuesday, 4 August 2015

How Does Lambdas Work In Java

In this post , i will show how lambdas in java work , with a simple example .Consider the following code snipped using java lambda .
package java8Test;

import java.io.File;
import java.io.FileReader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class LambdaTest2 {
  
  
  public static void main(String[] args) {
    
      ExecutorService service = Executors.newSingleThreadExecutor();
      service.submit(()-> {
        File f = new File("abcd.txt");
        FileReader reader = new FileReader(f);
        //use reader to read stuff
        return null ;
      });
  }
}
The above code compiles fine , now if you remove return statement(which seems redundant here) from above code , it fails to compile with following error :
Unhandled exception type FileNotFoundException
Reason for this behavior is , ExecutorService's submit method has two overloaded versions . One takes Callable , and the other one takes Runnable , Both methods have no arguments .

So , which one the java compiler chooses ?

It looks for return type as well . When you write return statement , it creates Callable and when you return nothing , it creates Runnable . Since Runnable does not throw Checked Exceptions , that is why you get compile time errors in the code .

You can explicitly cast it to Callable by using cast operator like this :
service.submit((Callable)()-> {
You can add marker interfaces also in the cast like this :
Callable calls = (Callable & Serializable) () -> { return null; };
Lambda Removes a lot of boilerplate code , but it might behave differently if you don't know how it works .
You can go to original link here

Thursday, 23 July 2015

Top Underrated Git Commands

Here are the most important commands in git , and their description .


git reset –hard origin/master 
Resets your Local Repo with HEAD
git reflog
Displays a walkthrough of git cycle through out your local repo with commit references.
git cherry
Note: Cherry and Cherry-pick are two different commands, Cherry displays a list of commit differences between branches/remotes
e.g git cherry master staging OR git cherry -v staging
git cherry-pick
Adds a commit to your current branch.
git shortlog
Displays Author and no of commits.e.g git shortlog -s -n
git shortlog
Everyone of us must be knowing what git logs can do , Today lets trick it out a advanced feature of Git log.
Lets take an example , Some one have merged master with staging and pushed accidentally.
I want to know who did it , who merged the changes because git will say the commit author name.
To do so we need to run
git log --pretty='%T %s --Commiter: %cn --Author: %aN'
Other method would be to open gitg and check author and committer name.
Author name is who changed the content in file and commiter is who merged or changed the commit history to your branch.

Thursday, 25 June 2015

Solved : Mule With Maven Failing

Recently , i encountered an error with maven build.

The pom file which i was using , started failing with failed dependency errors .It was working fine earlier.
Here is the error which i was getting while trying to build mule app with maven .

 Failed to execute goal on project middleware-services: Could not resolve dependencies for project com.javaroots:my-services:mule:1.0: Failed to collect dependencies at org.mule.transports:mule-transport-vm:jar:3.5.0 -> org.mule.modules:mule-module-xml:jar:3.5.0 -> net.java.dev.stax-utils:stax-utils:jar:20080702: Failed to read artifact descriptor for net.java.dev.stax-utils:stax-utils:jar:20080702: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project my-services: Could not resolve dependencies for project com.javaroots:middleware-services:mule:1.0: Failed to collect dependencies at org.mule.transports:mule-transport-vm:jar:3.5.0 -> org.mule.modules:mule-module-xml:jar:3.5.0 -> net.java.dev.stax-utils:stax-utils:jar:20080702
 at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:221)
 at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)
 at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:257)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200)
 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:116)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
 at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
 at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
 at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
 at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:287)
 ... 41 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
 at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute(BasicRepositoryConnector.java:581)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get(BasicRepositoryConnector.java:249)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:520)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
 ... 44 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.resourceExists(AbstractHttpClientWagon.java:724)
 at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.resourceExists(AbstractHttpClientWagon.java:680)
 at org.eclipse.aether.transport.wagon.WagonTransporter$PeekTaskRunner.run(WagonTransporter.java:518)
 at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
 at org.eclipse.aether.transport.wagon.WagonTransporter.peek(WagonTransporter.java:398)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PeekTaskRunner.runTask(BasicRepositoryConnector.java:376)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
 ... 49 more
The reason for failure of this is , Codehaus no longer serves up Maven repositories . So we need to change maven settings a little bit to make this work . Go to your M2_HOME/conf folder and open settings.xml .

Create following repo profile and activate it .
<profile>
   <id>mule</id>
  <repositories>
  <repository>
    <id>codehaus-mule-repo</id>
    <name>codehaus-mule-repo</name>
    <url>
      https://repository-master.mulesoft.org/nexus/content/groups/public/
    </url>
    <layout>default</layout>
  </repository>
</repositories>
 </profile>
<activeProfiles>
    <activeProfile>mule</activeProfile>
</activeProfiles>
And run the project again . It will work .

Ref : StackOverflow



Post Comments And Suggestions !!