Difference between ehcache and ehcache-core - java

I am beginner for ehcache v/s ehcache-core in Spring framework, my pom.xml used ehcache version 1.5.0
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.5.0</version>
</dependency>
Now, it will need to update ehcache version because it will use in another jar:-
Updated ehcache version 2.7.0
But it returns error
net.sf.ehcache.Cache.getStatistics() method not found.
Now, I am replacing ehcache via ehcache-core 2.5.7 as:-
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.7</version>
</dependency>
Is it break another functionalities or will work same as ehcache?

Just as many other large frameworks (like Spring), ehcache is split into several modules. One of those modules is core, the others are web, server, jcache, debugger and many more (see https://mvnrepository.com/artifact/org.ehcache.modules).
Sometimes, for various reasons, you may not want to include the entire large framework, with all its sublibraries, into your project. Then you can decide which module you want to use.
In other words, using ehcache pom will include a full library in your project. Using ehcache-core will only include functionalities defined in ehcache-core.
You can either find out which module contains the functionality you need and include it, or go with full ehcache but use the appropriate version.

There still is an ehcache module in version 2.5.7 but as it only pulls dependencies it's of type pom. One of those dependencies is ehcache-core. My guess is that your functionality won't be satsified with just that. Try
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.5.7</version>
<type>pom</type>
</dependency>

Related

What exactly means the configuration of this Spring data model project used by a Spring MVC application?

I am pretty new in Spring + JPA and I am working on a web application that use a project named model-gen-myapp.
This project contain the entity class annotated to map the database table (so it contain the model used by my web application to represent the data on the DB).
This is the pom.xml content of this project:
<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>model-gen-profdb</groupId>
<artifactId>model-gen-profdb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</project>
As you can see in the previous configuration it add some dependencies related to some Hibernate stuff and the spring-data-jpa Spring project.
For what exactly are used the previous dependencies?
Then if I select this project into the Eclipse project explorer and I do: Properties ---> Project Facets I find that the following facets are checked Java (version 1.7), JPA (version 2.1) and Utility Module.
What exactly is a project facets and what means the previous choice? I don't understand if this stuff add dependencies or if it something related to some project configuration?
Let me first introduce you to the mighty Maven here and please do some reading.
Dependency management is one of the most important features of Maven
which is best known to its users and is one of the areas where Maven
excels.
Your project is a JPA project, the hibernate-jpa-2.1-api is to provide you the JPA 2.1 APIs. You can access it here. It basically has these parent packages:
javax.persistence
javax.persistence.criteria
javax.persistence.metamodel
javax.persistence.spi
JPA is a specification from Oracle. The venders like Hibernate, Eclipse Link etc has the actual implementation of this specification. Hence you need the hibernate core hibernate-core jar. Read about Hibernate here.
Coming to spring-data-jpa. Spring Data JPA, part of the larger Spring Data family, makes it easy to implement JPA based repositories. This module deals with enhanced support for JPA based data access layers. It makes it easier to build Spring-powered applications that use data access technologies. Source: Spring Data JPA
Project Facets in Eclipse: An aspect which is to be used in the project, so that the IDE can intercept on it with regard to generators, wizards, auto-include libraries and so on. If you add for example the JPA facet, then you will get more options to do the IDE-magic with JPA. Here your project uses Java 1.7, JPA 2.1 and so on. Source: What is 'Facet' in JavaEE?
I hope this helps you!

how to restrict the 2 same jars are loaded with diffrent versions

I am using Apache Maven to building the project..
Problem is some jars are added two times with the different versions.
httpclient-4.0.3
httpclient-4.3.3
httpcore-4.0.1
httpcore-4.3.2
jackson-core-asl-1.6.7
jackson-core-asl-1.9.13
i want the higher version of jars
Usually what you would do is look first at the dependency tree and see where the same jars are coming from:
mvn dependency:tree
After you tracked down where the different dependencies come from you, as in your case, you pick the ones that are older and you go ahead and add a <exclusion/> tag inside the dependency that retrieves the older ones.
Example of how to exclude a dependency inside another dependency:
Let us presume you have hibernate and ehcache dependencies in your pom.xml. If hibernate 3.2.6.ga, for example, has inside ehcache, but it is an older version and we don't want that version. So in order to exclude ehcache from hibernate dependency we would do the following
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
Now, I would help you and add the correct exclusions to the dependencies that are retrieving your older dependencies, but since I am not able to see your pom.xml it is hard to help more.

most compatible hibernate version for spring 3.2.6

i use something like this at the moment: JSF2(PrimeFaces)+Spring&Spring-Security+JPA2(Hibernate). I just love it! But somehow i was always wondering: What are recommended (or maybe "best compatible") versions of specific Spring-versions with Hibernate? Let's take Spring 3.2.6 as an example:
If i take a look of spring-orm POM it seems like it uses hibernate-entitymanager 4.1.9.Final. Should i use that one, or maybe the newest 4.1.x version? Or should i use hibernate 4.2.x? Or even 4.3.x? In my (simple) tests any of that worked just fine, but then i read here https://jira.springsource.org/browse/SPR-11240 that hibernate 4.3 is not even supported until spring 4.
So to sum it up: Which hibernate version should i use with spring 3.2.6.RELEASE and what is the best place to find information like that (for the future).
The best way to be sure is to check the pom of the project for optional dependencies.
In this case, we can go to the maven repository and search for the project pom:
$HOME/.m2/repository/org/springframework/spring-orm/3.2.6.RELEASE
-rw-r--r-- ... spring-orm-3.2.6.RELEASE.pom
Opening the spring-orm pom, there is an optional dependency for Hibernate:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
An optional dependency can be seen as "excluded by default", and it's up to the project using spring-orm if they want to use that version or some other. It's a way for project developers to document the recommended versions for certain dependencies that they don't necessarily want to enforce in depending projects.
The optional dependency is the recommended version, other versions might or might not work but that version is the most tested.

How to add Spring libs using Maven

I learned Spring via Spring In Action 3 few month ago. I downloaded Spring libraries from official site (list was like in SIA3(aop, asm, aspects, beans ...)), added them to my project and everything worked fine. Now I want to use Maven, but I am getting a lot of errors and sinking in searching what library to add.
I am newby, dont know all Spring dependencies(within it libs) and the question is not about my errors, but about the way to add all Spring libraries to my project via Maven. How do you usually add Spring libs using Maven?
You don't have to download the libraries themselves anymore. That is what Maven is for. (and quite some more, of course)
set up Maven properly
set up Maven in the IDE tool you have (like this)
edit the pom.xml to include what you need, adding the dependencies in the in the dependencies tag.
Maven takes care of resolving the dependencies of the specified packages. If a package depends on other packages, it will do it for you. You only have to specify the packages you directly need
For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
You can easily find the packages using Google, and searching for "maven repository "
Avoiding version clashes
Also, as Bart mentioned, the common way of having Spring in the pom.xml - as it has way too many versions, and clashes can occur - is through a common property specifying the version for all Spring components. (Based on this answer)
Specify the property in the properties tag:
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
Then use it in the dependencies like this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Be careful to use it for ALL components to avoid version clashes. (of course, issues mught still occur, bz having different libraries reference spring too, but that is another story in its own.)
Side note
Keep in mind note that Maven projects use specific directory layout. When I first started using maven for my own projects, first I created a new blank one, and played around with it, before I began migrating my older projects to use maven. Believe me, it pays off.
Add spring artifacts to your pom.xml file. For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.4.RELEASE</version>
You can find more artifact info here
http://mvnrepository.com/
HERE you can find the dependencies as per your requirement. Just click on the dependency and inside click on the latest release, scroll down there is your code inside the <dependencies> Your required dependency and version</dependencies>.
Just copy the XML code and paste it in your pom.xml file.

Java Jersey Declarative Hyperlinks Configuration

I am confused by the Jersey Documentation Chapter 6
http://jersey.java.net/nonav/documentation/latest/linking.html
The configuration section (6.5) doesn't say where to add the dependency etc. What file(s) need to be edited?
I am confused what I need to do all together in order to use the #Ref attribute in my code.
EDIT/UPDATE
How do I use Jersey Hyperlinking without Maven. I've grabbed the jar file jersey-server-linking-1.9-SNAPSHOT.jar but I don't know what it depends on. Can some one give me a list of jars I need to get this working?
The dependency appears to be a maven dependency, So you'd put it in the typical maven configuration files, I'm not all that familiar with maven. This is really to make sure the Jersey linking module libraries are included in your application.
The rest of the code samples in that section refer to modifications you need to make to web.xml.
From the Jersey Hyperlinking POM,
here's the list of dependencies you need at runtime:
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
</dependencies>

Categories