I'm struggling with adding spring framework libaries to my eclipse (with maven plug-in m2eclipse)
How can I achieve it in easiest way and why is it so complicated for a newbe user?
It's really frustrating that I can't move on with thing that simple like this.
Main goal is add spring libaries to my pom.xml file in depedencies tab in my dynamic web project in eclipse. Pom.xml is generated thanks to maven plug-in.
First of all I moved to the Eclipse Marketplace and installed Spring Tool Suite for Eclipse Kepler 4.3 and the result is nothing - still can't add libaries. Second attempt was installing the same suite for my whole windows, nothing worked so far.
Sample screenshot (all I can add is this):
Where is spring-web, spring-context, spring-webmvc etc. ? For me it's night and I don't have fresh eye on it but what am i missing here?
I have been using the Spring Framework and Java within Eclipse for a while now. And to be completely honest, the UI for pom.xml completely sucks. Just avoid the Eclipse UI for Maven and manipulate the raw XML. It is very intuitive and powerful.
So if you want to add a dependency, start using mvnrepository. From there you can get all the dependency snippets you need.
For 'spring-web' insert
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
In the <dependencies></dependencies> section. And you are set.
The same can be done for context and webmvc.
Just for convenience here is spring-webmvc:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
and here is spring-context
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
Related
I was trying to migrate Hibernate 3 to Hibernate 5.0.11 and I have downloaded and imported the Hibernate 5.0.11 core jar files. But when I try start my apache tomcat server on my IDE, it shows the error
org.springframework.beans.factory.BeanCreationException
org.springframework.beans.BeanInstantiationException:
This is because I am not able to download the Spring-Hibernate5 jar files.
Can anyone guide me to download and install those jar files.
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
Thanks in Advance.
I would not recommend you to download and manage your dependencies manually, since you can forget a required lib. Just let Maven (or other dependencies management tool) handle it for you:
<dependencies>
<!-- Other spring libs -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.11.Final</version>
</dependency>
</dependencies>
The class is located into spring-orm project, since its version 4.2.
However, it is already known that HibernateDaoSupport is not the best solution for your purposes anymore, take a look: Why is HibernateDaoSupport not recommended?
Supppose I use spring 4.0 in my pom file and I want to use junit. In that case how can I declare the junit dependency to download the which compatible with the given spring version with out specify any specific junit version. This can be any dependency where I take junit as a example.
In Maven there are two possible matching things. First the dependency management of the artefact itself. spring-core:4.2.0 defines that it depends on commons-codec:1:10. So there is nothing to do for you when you want to also use commons-codec since its already in your classpath. It did not define JUnit so it did not depend on it and should be compatible with all versions.
The second thing is aBOM pom. This is used to package a lot of dependencies together and let the user select the once he needs but the bom defines the versions for you already (and so they should be compatible). Especially spring has some of this bom poms in the repo.
For example spring-framework-bom which packaged everything related to spring which you could use in your app but you will define which parts you need and do not bothering yourself with the version numbers of the sub dependencies.
For example I want to use spring 4.2 and need webmvc the jdbc stuff and something for spring tests. So will define this:
<dependencymanagement>
<dependencies>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-framework-bom</artifactid>
<type>pom</type>
<version>4.2.0.RELEASE</version>
<scope>import</scope>
</dependency>
<dependencies>
</dependencymanagement>
<dependencies>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-webmvc</artifactid>
</dependency>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-jdbc</artifactid>
</dependency>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-test</artifactid>
<scope>test</scope>
</dependency>
</dependencies>
This question doesn't really make sense. If spring 4.0 depends on JUnit (you don't say which spring module you're referring to), JUnit (or any other dependency) will automatically be included in your dependencies, since it will be inherited from the spring 4.0 dependency you have already declared, and the version will match whatever version the Spring module declares in its POM.
However, it seems likely that your particular Spring 4.0 dependency does not depend on JUnit, so in which case you may just pick which ever version is suitable for your requirements.
You can view the dependencies which are currently included in your project (explicit and inherited) by running the following command:
mvn dependency:list
This will trace down the dependency tree and show you all the dependencies which are currently included in your project.
My webapp includes REST web services and is running on GlassFish 3.1.2.
I would like to run this app on Tomcat 7 instead of GlassFish. What dependencies should I add and remove to enable REST services on Tomcat?
(At the moment I just changed "GlassFish" to "Tomcat" in the "Run" menu of Netbeans, but my http requests give a 404.)
Note: this is a Maven project on Netbeans.
Ok here is the list of dependencies you may need. Please note I just put latest version but you may want to use a different version. Please also check for compatibility of these versions with each other.
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
Needed if you are using jackson to parse json
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.3.3</version>
</dependency>
This is what I am using on my tomcat but little bit older versions
Now about your 404
First check if the dependencies fix your problem. 404 may be an issue from some thing not configured right in your web.xml as well.
I hope it helps you solve your problem :)
I need to use AOP of Spring in Eclipse. So I tried to use '#Aspect' annotation, but it does not found it and just suggest me to create myself. As I understand Spring itself does not have this annotation? Because in documentation it shows that is uses aspectj. So I downloaded from http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/aspectj-1.7.4.jar
Then added it as external jar from project properties. But still nothing changed. Did I miss something?
Update:
I also installed AJDT via plugin manager, but still it does not recognize '#Aspect' annotation. So what should I do so it would recognize it?
You are right, you need both the aspectj plugin and the spring aspect plugins.
First, make sure you have the proper maven dependencies in your project. It should be:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${version}</version>
</dependency>
And modify the versions by the ones you would like to use.
Then if you use a maven plugin for Eclipse like m2e it should find the dependencies.
Hope that helps
I'm trying to build a Maven based Java EE project on Jenkins, but I'm getting compilation errors. The reason seems to be that the Java EE dependencies that are marked as provided in the POM logically enough aren't downloaded when the project is built.
How can I set up the POM so that the build works in Jenkins, but the EE dependencies aren't included in the WAR file?
My thanks in advance for any input you can provide.
That's strange, AFAIK the dependencies with scope "provided" are simply not placed in the built file, they should however be downloaded. Are you sure your Maven is correctly configured to download dependencies - maybe there's a proxy that's not configured.
Not sure if its the best solution, but you can add EE dependencies with scope "provided", like the example:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.27</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Maybe there is a plugin who provides all of them to you, but I'm not sure about that.
Hope that helps