Question

I have developed a tutorial of RESTFUL web services long ago.Now i have imported the same project in my eclipse,but i do not remember anything how I made this project run earlier.And i would like to know little more information about the significance of POM.XML and other dependencies.

1.Is it necessary to build the project using Maven build? which will give pom.xml

2.If yes,is pom.xml the place where we will be defining the dependencies? like jars needed to read some excel file?Is this the same place where I can define dependency and it will get downloaded auomatically.

3.Do i really need a maven build for this? I have simple class and DAO and BEAN for this.

import java.io.IOException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import Bean.bookBean;
import Dao.bookDao;
@Path ("login")
public class bookPost {

@GET
@Path("validate")
@Produces(MediaType.TEXT_PLAIN)
    public String login(@QueryParam("frition")String un,@QueryParam("thriller")String pwd) throws IOException
{
    bookDao dao=new bookDao();
    bookBean tt=new bookBean();
    tt.setFrition(un);
    tt.setThriller(pwd);

    return dao.loginValidate(tt);
    }
}

My bookCategory class

import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import Bean.bookBean;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

    public class BookCategories {

        private String inputFile;
        public void setInputFile(String inputFile) {
            this.inputFile = inputFile;
        }

        public void read() throws IOException  {
            File inputWorkbook = new File(inputFile);
            Workbook w;
            try {
                w = Workbook.getWorkbook(inputWorkbook);
                // Get the first sheet
                Sheet sheet = w.getSheet(0);
                // Loop over first 10 column and lines

                for (int j = 0; j < sheet.getColumns(); j++) {
                    for (int i = 0; i < sheet.getRows(); i++) {
                        Cell cell = sheet.getCell(j, i);
                        CellType type = cell.getType();

                        if (cell.getType() == CellType.LABEL) {
                            System.out.println("books "
                                    + cell.getContents());
                        }
            }
                }
            } catch (BiffException e) {
                e.printStackTrace();
            }



        }

        public static void main(String[] args) throws IOException {
            ClientConfig config = new DefaultClientConfig();
            Client client = Client.create(config);
            WebResource service = client.resource(getBaseURI());
            // Fluent interfaces
            bookBean lbean = new bookBean();
            lbean.setFrition("frition");
            lbean.setThriller("thriller");
            String cr =service.path("login").path("postvalidate").post(String.class,lbean);
            System.out.println(cr);
}

private static URI getBaseURI() {
    return UriBuilder.fromUri("http://localhost:8080/Services").build();
}

        }

4.When do we really require a POM.XML? and as of now it is showing errors for poi jars.I have dowloaded them manually and placed the files added to the project also.Still if I run the project on APACHE TOMCAT 7 server the following error comes up in console.

Error May 13, 2014 2:44:05 PM com.sun.jersey.api.core.servlet.WebAppResourceConfig init
INFO: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
May 13, 2014 2:44:06 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No root resource classes found.
May 13, 2014 2:44:06 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
  class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
  class org.codehaus.jackson.jaxrs.JacksonJsonProvider
  class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
  class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
May 13, 2014 2:44:06 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.12 02/15/2012 04:51 PM'
May 13, 2014 2:44:06 PM com.sun.jersey.server.impl.application.RootResourceUriRules <init>
SEVERE: The ResourceConfig instance does not contain any root resource classes.
May 13, 2014 2:44:06 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1308)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:171)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:777)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:773)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:773)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:768)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:607)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1133)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1087)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:799)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

May 13, 2014 2:44:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Ebook
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1308)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:171)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:777)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:773)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:773)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:768)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:607)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1133)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1087)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:799)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I have tried to found this on other forums.But i am simply getting lost in the middle as I have many questions in mind.Spend around 4 hours but not moving ahead.Hoping for a clear and crisp info.

Was it helpful?

Solution

After little research and few days of Brain-Storming with MAVEN.I am able to answer my question myself.

1. No it is not a compulsion to build a project using maven build or ant build or any other build.But if you are using MAVEN it will definitely have pom.xml where you will be defining dependencies,details of packaging the JAR's.

The process of build generally means it will start with the source file you have written and ends up in something like jar or war which can be deployed on server.

2. Yes you can define the compile time and run time dependencies.If you want to know about [compile time and run time dependencies](http://stackoverflow.com/questions/4270950/compile-time-vs-run-time-dependency-java).And yes it also provide you the feature to download the required jars when you will be building the jar in a different machine then yours using that pom.xml.

3. If you want to package it in jar and define dependency you need MAVEN.Else you do not need maven build for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top