I'm following a tutorial on Vogella on how to work with JAX-RS to create RESTful web applications.
The trouble for me is that I am not able to import the dependencies through Maven. Is it possible?
When I try finding jsr311 or javax.ws.rs as suggested here, Maven doesn't seem to know it exists.
If you are satrting your project from scratch, it would be better to let maven generate your project for your using one of the Maven Archetypes that Jersey provides (More in the Jersey getting-started page) then you can easilly add the eclipse nature to the generated project using below command:
mvn eclipse:eclipse -Dwtpversion=2.0
Choose your suitable Web Tool version, then import that project into your Eclipse IDE.
This method, will leave you out of poviding any dependencies related to Jersey as those are already mentioned in the archetype descriptor.
Otherwise, if you are already working on a project and you want to add the RESTful features (which assume is not true since you mentioned that you are following a tutorial), you will have to provide dependencies to Jersey yourself. All dependencies can be found in Maven Central Repo but you would only need the jersey-server one:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
As #Gimby stated, there is absolutely no sense in declareing the jsr311-api alone, only if you are intending to provide a JSR implementation :)
please try as following:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
Ended up finding a similar question here.
Solved the problem by manually adding the dependency under pom.xml:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
foun it on : (http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1)
it will work inchalahh ;D
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>
Related
I'm trying make a project using Jsoup library.
I imported the library using maven.
My problem is when I have start to code using Jsoup classes and methods, eclipse don't show me anything available to import and to use from "org.jsoup"
I've already used Maven update project but my project has all dependencies placed right.
Someone got this problem too and could help me?
That is my current pom.xml on dependencies section:
<build>
<finalName>crawler-api</finalName>
</build>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
and my project libraries screenshot:
project libraries
Well. After some struggles I will leave some details about what I did to solve my problem.
Unfortunately for some reason if you try add Jsoup library from maven repository I can get the classes and methods from the api.
I found some comments on github from people who said that the only solution for that is including the jars into your project. What sounds a bit old fashion.
Well. Let's get started.
First, create a folder called lib into src/main/webapp/WEB-INF/ and have included the jsoup .jar that I have downloaded from the official web site.
After that I've added into pom.xml on dependencies section the follow child tag.
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/jsoup-1.11.2.jar</systemPath>
</dependency>
So when I've started code my app using the classes and methods from the api everything seems available when I called. And after that when I built my artifact using maven the dependencies has been available inside my artifact.
I really hope this could help someone. And I hope that the developers of Jsoup somehow fix that.
What I want to do is to add Swagger to my REST Api based on Jersey 2.x.
But it seems Swagger for Jersey is based on Jersey 1.x.
When I added the Swagger dependencies in Maven I get the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:119)
I think this is because
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey-jaxrs_2.10</artifactId>
<version>1.3.1</version>
</dependency>
has dependency to
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.13</version>
</dependency>
And this is in conflict to the Jersey 2.x my application is using.
Is there a Swagger integration for Jersey 2.x available?
Any ideas how to solve my problem otherwise?
Use the following dependency instead:
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
<version>1.3.10</version>
</dependency>
And that should solve your problem. We're going to release a new tutorial on how to integrate with jersey/jersey2 soon.
I'm afraid swagger-jersey2-jaxrs_2.10 in Ron's answer is outdated.
Per https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5, here is an updated dependency to use (as of Feb 2016):
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
Ive been using anotation for my beans (I havent used them before) and I found out I have to include some dependencies and so on, like this:
<!--JSF API-->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2</version>
</dependency>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3</version>
</dependency>
<!-- JSF -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<!-- Javax Servlet. This needs to be included for runtime only! -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
and well.. the problem is that the I keep getting the error of
The import javax.faces cannot be resolved
Every time I need to use the managed bean... I am using Maven and I am supposed to have downloaded all things I need, I also tried other POM and in that project I can use anotations, so, I guess is a misconfiguratino of the POM? I didnt do anything special to ecplise, except enable the maven clean, maven eclipse, and maven eclipse skip test
I really checked other answers, like these:
The import javax.servlet can't be resolved
How do I import the javax.servlet API in my Eclipse project?
but nothing, any idea what could be wrong??
You should not import the servlet API but implementation of the API, for example the servlet container implementation you want on which you want to run your project : Tomcat, JBoss, Websphere, Glassfish....
E.g. for tomcat :
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
Thanks for the answer, I checked that using Maven its a little bit different and in the built path you have to specify the path for your maven repository, so, it will incluide all libraries directly or you can copy and past them into your project
I need to import javax.jms.* classes. What is the right dependency to include into a Maven project? I'm trying javax.jms:jms:1.1, but no luck (it's pom, not jar).
ps. The only workaround I've found so far is: javax:javaee-api:6.0 (from Maven Central).
In ActiveMQ as well as some other projects like Qpid JMS we pull in the JMS spec classes from Apache Geronimo JARs, the 1.1 APIs are available in this dependency:
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>
For JMS 2 APIs you'd need to use a different dependency, for instance
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
<version>1.0-alpha-2</version>
</dependency>
These are both Apache 2.0 licensed dependencies.
Another option which is not Apache licensed is here as others have pointed out.
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
The Sun license doesn't allow maven repositories to host this (and other) artifacts.
Here is the documentation explaining this and what you should do instead...
Maven - Guide to coping with Sun JARs
What it says is you need to download the JAR manually and then install it into your own local repository or nexus server.
The pom.xml files hosted at maven central for these artifacts contain information on where you can download the JARs from.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
I have successfully used this one:
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
Go to Maven Search site and search for javax. Open the latest version for groupId javax and artifactId javaee-api
The current version is 7.0 [Maven dependency information]
If you just want the JMS libs, without the rest of javaee, use the following:
https://mvnrepository.com/artifact/javax.jms/javax.jms-api/2.0.1
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
According to mvnrepository, the dependency to add in the pom of your project is the following:
<dependency>
<groupId>jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
Check out the dependencies listed on grepcode.com.
I only discovered this site recently, and it rocks!
http://grepcode.com/search/?query=javax.jms.*
It looks like the Geronimo jars on maven central should sort your issues out.
This worked for myself
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
I am trying to use Spring LDAP for coding
<ldap-server ldif="classpath:my-ldap-clone.ldif" />
but I get this error
NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
What am I doing wrong?
Using maven :
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.7</version>
</dependency>
If you are using Maven, these actually come from an optional dependency of spring-security-ldap.
Using apacheds-all is a bad idea because it embeds a lot of rather common dependencies, like slf4j and dom4j. You would easily get into classloader issues with it.
Instead, you should look inside the pom of the spring-security-ldap version your are using, for the apacheds optional dependencies, and copy them over to your pom without the <scope> and <optional> elements (unfortunately there is no better way to handle optional dependencies with Maven).
For instance, with spring-security-ldap 4.2.2, it would give:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core-entry</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-ldap</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-shared</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>1.5.5</version>
</dependency>
(it looks like it hasn't changed since at least 3.2)
Download ApcheDS from below link
http://directory.apache.org/ or get complete jar from here
I have used to work with Spring Security 3.0.5 with LDAP (Spring LDAP 1.3). That time i didn't met requirement of ApacheDS. Check your version of Spring Secuirty which may have dependency with ApacheDS.