java - jersey server missing dependencies -
i'm using code:
import java.io.file; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstream; import java.io.outputstream; import javax.ws.rs.consumes; import javax.ws.rs.post; import javax.ws.rs.path; import javax.ws.rs.core.mediatype; import javax.ws.rs.core.response; import com.sun.jersey.core.header.formdatacontentdisposition; import com.sun.jersey.multipart.formdataparam; @path("/files") public class jerseyfileupload { private static final string server_upload_location_folder = "c://users/nikos/desktop/upload_files/"; /** * upload file */ @post @path("/upload") @consumes(mediatype.multipart_form_data) public response uploadfile( @formdataparam("file") inputstream fileinputstream, @formdataparam("file") formdatacontentdisposition contentdispositionheader) { string filepath = server_upload_location_folder + contentdispositionheader.getfilename(); // save file server savefile(fileinputstream, filepath); string output = "file saved server location : " + filepath; return response.status(200).entity(output).build(); } // save uploaded file defined location on server private void savefile(inputstream uploadedinputstream, string serverlocation) { try { outputstream outpustream = new fileoutputstream(new file( serverlocation)); int read = 0; byte[] bytes = new byte[1024]; outpustream = new fileoutputstream(new file(serverlocation)); while ((read = uploadedinputstream.read(bytes)) != -1) { outpustream.write(bytes, 0, read); } outpustream.flush(); outpustream.close(); } catch (ioexception e) { e.printstacktrace(); } } }
when try run on apache tomcat these error messages:
severe: following errors , warnings have been detected resource and/or provider classes: severe: missing dependency method public javax.ws.rs.core.response com.javacodegeeks.enterprise.rest.jersey.jerseyfileupload.uploadfile(java.io.inputstream,com.sun.jersey.core.header.formdatacontentdisposition) @ parameter @ index 0 severe: missing dependency method public javax.ws.rs.core.response com.javacodegeeks.enterprise.rest.jersey.jerseyfileupload.uploadfile(java.io.inputstream,com.sun.jersey.core.header.formdatacontentdisposition) @ parameter @ index 1 severe: method, public javax.ws.rs.core.response com.javacodegeeks.enterprise.rest.jersey.jerseyfileupload.uploadfile(java.io.inputstream,com.sun.jersey.core.header.formdatacontentdisposition), annotated post of resource, class com.javacodegeeks.enterprise.rest.jersey.jerseyfileupload, not recognized valid resource method. nov 19, 2014 11:44:41 org.apache.catalina.core.applicationcontext log severe: standardwrapper.throwable com.sun.jersey.spi.inject.errors$errormessagesexception @ com.sun.jersey.spi.inject.errors.processerrormessages(errors.java:170) @ com.sun.jersey.spi.inject.errors.postprocess(errors.java:136) @ com.sun.jersey.spi.inject.errors.processwitherrors(errors.java:199) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:795) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:790) @ com.sun.jersey.spi.container.servlet.servletcontainer.initiate(servletcontainer.java:491) @ com.sun.jersey.spi.container.servlet.servletcontainer$internalwebcomponent.initiate(servletcontainer.java:321) @ com.sun.jersey.spi.container.servlet.webcomponent.load(webcomponent.java:605) @ com.sun.jersey.spi.container.servlet.webcomponent.init(webcomponent.java:207) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:376) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:559) @ javax.servlet.genericservlet.init(genericservlet.java:158) @ org.apache.catalina.core.standardwrapper.initservlet(standardwrapper.java:1241) @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1154) @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:1041) @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4932) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5218) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1396) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1386) @ java.util.concurrent.futuretask.run(futuretask.java:262) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745) nov 19, 2014 11:44:41 org.apache.catalina.core.standardcontext loadonstartup severe: servlet /asdf threw load() exception com.sun.jersey.spi.inject.errors$errormessagesexception @ com.sun.jersey.spi.inject.errors.processerrormessages(errors.java:170) @ com.sun.jersey.spi.inject.errors.postprocess(errors.java:136) @ com.sun.jersey.spi.inject.errors.processwitherrors(errors.java:199) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:795) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:790) @ com.sun.jersey.spi.container.servlet.servletcontainer.initiate(servletcontainer.java:491) @ com.sun.jersey.spi.container.servlet.servletcontainer$internalwebcomponent.initiate(servletcontainer.java:321) @ com.sun.jersey.spi.container.servlet.webcomponent.load(webcomponent.java:605) @ com.sun.jersey.spi.container.servlet.webcomponent.init(webcomponent.java:207) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:376) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:559) @ javax.servlet.genericservlet.init(genericservlet.java:158) @ org.apache.catalina.core.standardwrapper.initservlet(standardwrapper.java:1241) @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1154) @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:1041) @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4932) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5218) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1396) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1386) @ java.util.concurrent.futuretask.run(futuretask.java:262) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:74
what mean? how can fix these dependencies?
thanks in advance!
upd 0 dependencies:
<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.javacodegeeks.enterprise.rest.jersey</groupid> <artifactid>jaxrs-helloworld</artifactid> <version>0.0.1-snapshot</version> <repositories> <repository> <id>maven2-repository.java.net</id> <name>java.net repository maven</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> </repository> </repositories> <dependencies> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-server</artifactid> <version>1.9</version> </dependency> <dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-multipart</artifactid> <version>1.9</version> </dependency> </dependencies> </project>
most jars aren't getting transferred tomcat when deploy it. 1 thing can see being problem, missing <packaging>
in pom.xml
. if missing, default build .jar
. need .war
dependencies put web-inf/lib
.
so add <packaging>war</packaging>
right under project <version>
. clean , package project. should .war
file. if explode .war
, should see web-inf/lib
. standard place webapp dependencies. without exploding it, can add war to tomcat webapp
dir , when start tomcat, should explode .war
, should able find libraries there.
i had no problem running example after adding this.
Comments
Post a Comment