Using different eclipselink than bundled in glassfish-embedded-web - glassfish

I use glassfish-embedded-web for integration tests inside a maven project:
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-web</artifactId>
<version>3.2-b06</version>
<scope>test</scope>
</dependency>
glassfish-embedded-web comes with Eclipselink 2.2.0, but the project requires features of 2.4. For regular deployment, this is solved by adding je required jars to glassfish's modules directory and this dependency:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
I tried also compile scope, still the embedded EL 2.2.0 is used. Adding a test scope dependency on EL 2.4.1 doesn't help. Is there any way to solve this?

Did you try to specify the maven scope test? Otherwise it will not be available while testing! To only provide this version for testing you could use maven profiles.

I see two possible solutions to this problem: either you build your own glassfish-embedded or you just use a brute force approach and modify the jar.
On the 1st approach:
After spending some time building GF I figured that even with my dilettante shell scripting skills its easier to just use the second approach instead of figuring GF code. However, if you're up for this one I'd suggest to start at oracle wiki.
On the 2nd approach: As I've mentioned above, automating this task is the best approach in my opinion (at least if you're dealing with numerous libs and continuous changes), so I wrote this script with all the necessary instructions on how to use it. After you get the new jar just install it in your local repo. I'm using Nexus so for me it was a matter of couple buttons getting pressed.
P.S.: Any comments/advices/improvements on the script are welcome.

Related

How to add Java EE Servlet API library on your compile classpath in IntelliJ

I am new to IntelliJ and I have been working on a few small projects to familiarize myself with IDE and how to develop Java web projects with it.
I recently picked up Professional Java for Web Applications to practise my web development skills and I wanted to try it because it focuses on IntelliJ rather than Eclipse.
My main issues are from not knowing my way around the IDE at all. I have come across a problem that I have been unable to figure out how to do correctly.
How do you add Java EE Servlet API library on your compile classpath ?
Where is the compile classpath located in IntelliJ ?
Any help is appreciated!
This depends on how you are managing dependencies in your project.
If you are using Maven simply add it as a dependency in your pom.xml. When IDEA sees a maven based project it will over for you to Import Changes and/or Enable Auto Import. A common JavaEE 7 maven dependency would look like this in your pom.xml:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
If you are only using an IDEA project to manage things (vs. maven, gradle etc.) then you can go into the project structure dialog, click on modules and select the module containing your web tier code. Then click on the dependencies tab. Then click on plus button (+) and add a JAR, then navigate to the JAR containing the servelet APIs that is bundled with your application server and select that.
There are another half dozen ways to set this up and exactly which one you choose depends on a lot of factors like how you want to manage provided dependencies in your project etc. Either of these methods should get you on your way though.

How do I install Robot framework and selenium 2 library with Jython?

I searched a lot regarding this. Still I didn't get any definite answer for this. Someone Please explain me on how to do this. Please mention the compatible versions also.
You can use the Selenium 2 java robot framework.
Just add the following dependency to the pom file (if you use maven)
<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>robotframework-selenium2library-java</artifactId>
<version>1.4.0.6</version>
</dependency>
If you don't use maven, just download the jar from
https://github.com/MarkusBernhardt/robotframework-selenium2library-java
(You can find a link there to the jar with the dependencies in it)
This is compatible with all jython versions (since it's java based)

Maven dependencies for a library that uses JSF and should work with either Mojarra or MyFaces

We have a library that contains small additions to functionality provided by JSF (things like additional ResourceHandlers).
As it uses JSF classes (from javax.faces.* packages), it naturally must depend on the JSF API. The library is packaged as a Maven project, and depends on com.sun.faces:jsf-api.
This works fine for compiling, and for use in projects that use Mojarra. However, if we include the library in a JSF application that uses MyFaces, we get errors, as described in Exception: could not find Factory: javax.faces.context.FacesContextFactory .
Apparently, if an application uses MyFaces, it must use myfaces-api.jar and myfaces-impl.jar (or the corresponding Maven deps), and not jsf-api.jar or jsf-impl.jar.
This leaves me a bit confused.
Why do Mojarra and MyFaces use different API jars? Both implement the same API (JSF), so shouldn't they use the same API jars?
I thought the whole point of having seperate "api" and "impl" jars was that only the "impl" part has to be switched to use a different implementation. Did I misunderstand something?
More concretely: What is the right Maven dependency for a library that should only depend on the JSF API? Right now, we depend on jsf-api, and projects that use MyFaces must use <exclusions> to throw out jsf-api and include myfaces-api. That works, but surely there is a better way?
Maybe they use different API jars because of some distribution / licensing issues. I dont know exactly.
But the API is the same, your FacesContextFactory can be found in the myfaces-api jar as well.
I would try to create profiles (or even two separate modules) that define the according set of dependencies. Using profiles you would need to activate one of them manually to switch the dependencies. With modules both would be built but the question where to put your sources will arise but the dependencies can be set to compile so it will be easier to create a deliverable.
It may be worth looking at Gradle here - I always had issues with projects that need to adopt different sets of dependencies and I've seen some nice features there.
Sorry I have no good solution found yet for this setup either.
edit: while thinking: you may just create two branches in your SCM and merge changes between them? (beside the dependencies of course)
Why do Mojarra and MyFaces use different API jars? Both implement the
same API (JSF), so shouldn't they use the same API jars?
They are seperate implementations of JSF. JSF is a Specification. See this Question.
More concretely: What is the right Maven dependency for a library that
should only depend on the JSF API? Right now, we depend on jsf-api,
and projects that use MyFaces must use to throw out
jsf-api and include myfaces-api. That works, but surely there is a
better way?
What you are terming "The JSF API" is the Sun/Oracle implementation of it (Mojarra). The dependencies for these are:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.2</version>
</dependency>

Versioning for a maven project with small, very frequent releases

I'm converting an ant project to a maven one. This project differs from the ones I've usually converted since it has very frequent releases, typically 8-10 times per day.
By release I mean that the resulting jar is packaged and included in the production enviroment. This project is a leaf one, so it publishes no API, it only consumes it. It is also at most a runtime dependency for two other projects.
I'd like to have a versioning scheme where:
it's easy to deploy without forcing the developers to think about what version number to assign to the project, since the number is meaningless;
It's easy to include the latest version of this project as a dependency without constantly bumping up dependency versions;
Most likely the dependency version would not be a -SNAPSHOT, since that would conflict with the maven-release-plugin we're using for other projects, but I'm open to suggestions.
Actually, you can use x-SNAPSHOT version and still use the maven-release-plugin. Just use mvn release:prepare before mvn release:perform to prepare your release and change the version in the poms from x-SNAPSHOT to a new version (you will be prompted for the versions to use). You can check out this introduction to the maven-release-plugin for a quick overview of release:prepare and release:perform.
Then, to include the latest version without constantly updating dependencies version, you could use dependency ranges like in the following snippet where we specify a range Junit 3.8 - Junit 4.0:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>[3.8,4.0)</version>
<scope>test</scope>
</dependency>
A version before or after the comma is not required, and means +/- infinity. For example, [4.0,) means any version greater than or equal to 4.0.
Personally, I don't like to use dependency ranges that much because I find that it can lead to build reproducibility issues and makes the build more fragile.
But you may have good reasons to use them.

In what maven2 repository can Google Guice be found?

As far as I understand Google Guice 2.0 is out not so long ago. But I see that central repo still has outdated 1.0 version. Please, tell where can I find maven2 repository with Google Guice 2.0.
Guice 3.0 is now available on central. You'll need the following to depend on it.
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
Sadly, they haven't uploaded source jars, and the class files have been compiled with Java 6. This may be a show-stopper for you…
Guice 2.0 is now available in the official google-maven-repository. To use it, add the following to your pom.xml inside of the <dependencies> tag (you'll need to add one if there isn't one):
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
You shouldn't need to, but you can add a reference to the official google-maven-repository in your pom.xml by following the instructions here.
Since I don't see Guice 2.0 in central I thought I'd include a stable repo where I found it:
https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/
The Grails OpenID plugin references http://guice-maven.googlecode.com/svn/trunk/ but that doesn't have it (currently).
They will put it to the central repository soon, as they promised here: http://groups.google.com/group/google-guice/browse_thread/thread/6707a887ed5ef2e3
Never mind. Guice-maven is intended to provide this.
Until it reaches the central repository, I've been getting it from here: http://guice-maven.googlecode.com/svn/trunk