How to integrate standalone Java EE 6 inside Eclipse IDE - java

I am facing issue with Maven 3.x where I am getting Guice Provision error.
With further debugging and investigation, I found the core issue that it is due to Java EE 6 not present inside my Eclipse IDE (Java EE 5 is there with one web server installed) and Guice library is looking for some Java Class which is available with Java EE 6.
Is it possible that I integrate the standalone JavaEE 6 inside Eclipse IDE without installing any webserver or updating the current one?

You can add a maven dependency for Java EE 6 (http://search.maven.org/#artifactdetails%7Cjavax%7Cjavaee-api%7C6.0%7Cjar) to your project, and eclipse will gladly understand it.
However, your runtime will also need to be a Java EE 6 compliant container. Otherwise, you'd simply be looking for trouble. You may run into problems at runtime if you use a pre-Java EE 6 container (especially if you use newer features -- such as CDI).
Alternatively, if your library wants a specific feature (like, as I dare to guess, the CDI api), then you can add just the CDI jars to your classpath (check http://search.maven.org/#artifactdetails%7Cjavax.inject%7Cjavax.inject%7C1%7Cjar)

Related

Migrating a Maven JEE 7 Project to JEE 6

There is a requirement for one of our apps built as a Maven JEE 7 project (which typically runs on Jboss AS7) to be able to run on Jboss AS6 and effectively converted to a JEE 6 project.
I am assuming that a simple change to the maven javaee-web-api dependency from version 7 to the older version 6, will do the job but being fairly new to Maven I don't know for sure.
Also not sure if I could use another approach - if there is a specific maven archtype available that can help convert the project. Any guidance on achieving this is appreciated.

Javax.persistance not available in TomEE

When running my Java EE app on TomEE I get the following error:
java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
There are no compile time errors when I build the app.I am developing in Eclipse and have Apache TomEE selected under targeted runtimes in the project properties, so that the project has access to Java EE.
As the project uses Hibernate I have the following jars in the WEB-INF\lib directory (it's my understanding that these jars in turn use javax.persistence):
hibernate-commons-annotations-4.0.4
hibernate-core-4.3.5
hibernate-jpa-2.1
I've seen a bunch of questions like this one detailing that the solution is to add the required JPA jar into the lib directory of the app and all will be well. But although that solution may work it sounds hacky to me, I want TomEE to manage the JPA libraries itself. It's a Java EE server so why doesn't it do this. Whats a clean solution?
#JB Nizet's answer is the accepted solution:
This class exists since JPA 2.1. I guess your TomEE version only
supports JPA 2.0. And indeed, thehome page of TomEE says: "Java EE 6
Web Profile". Java EE 6 includes JPA 2.0, not 2.1. – JB Nizet

Setting up Java and Eclipse IDE - Redundant installations

Am I doing the same thing by installing the Java EE package from the official Java website and installing the Eclipse IDE for Java EE developers? Do they have the same components?
No they do not have same components!
Difference between Eclipse for Java EE and Classic version of Eclipse with Java EE libraries is that you have editors for various things like HTML to JSP/JSF. You also have additional functionality like servers to configure. But irrespective of Eclipse you are using you need the java EE library to run your apps. So you either install Java EE SDK(and then configure Eclipse to use this SDK) or use a dependency manager.
When you download Eclipse IDE for Java EE you get tools for developing EE applications. For eg. XML editors and tools, servers etc. Before you start running your EE applications you have to specify installation path for your server like Tomcat or Glassfish which is also a part oh your Java EE SDK installation. These servers containers provide the runtime libraries needed for your dynamic web projects to run. Yes you still need the libraries at compile time which is why most programmers use some dependency manager like Apache Ivy or Maven. Also Java EE libraries like javax.annotation you have to provide it in dependency manager.
So if I just installed Java SE first and then Eclipse for Java EE, wouldn't I have the Java EE libraries?
No! So when you install Java SE you will get standard java libraries.When you install Eclipse(and configure it to use Java SE SDK you just installed) for Java EE(including server) you will have all the tools required to configure and run web application. But if you want EE functionality you need to add those corresponding libraries - either install SDK or use dependency manager. So both - Eclipse for Java EE and Java EE SDK are really two different things and you need both to run Java EE applications.

How to set java EE version for liferay ide

I was using java 6 SE, but now, when i used wsdl2java, it generated class using javax.xml.ws.Service in EE version, so i have downloaded and installed java 6 EE, but i'm not sure where should i change java version from SE to EE in my portlet project.
I have installed few tomcats and glassfishes servers, including one downloaded from oracle website as "java ee sdk" package (http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-6u3-downloads-439814.html). Still i have no idea where I can locate jre that uses EE api instead of SE api. I googled that there should be directory glassfish3/jdk, but there is nothing like this.
Only JREs i can find are java 6 and 7 SE.
Finally found out how to do that. First, you need to download java EE API (empty signatures, without method code bodies) packed as jar. It can be downloaded from maven central repo.
http://search.maven.org/ + javaee.api gives result of http://search.maven.org/remotecontent?filepath=javax/javaee-api/6.0/javaee-api-6.0.jar (i'm using jre 6).
Now i put that jar into my portlet project. In eclipse its:
project settings -> Java Build Path -> Libraries -> Add External JARs...
Then after java ee api jar is inside of project, you must move it above SE JRE:
project settings -> Java Build Path -> Order and Export
And thats it. You can work with EE API without any errors. Keep on mind that this jar provides ONLY empty API. Such application must be deployed to java EE driven server, most likely you want to deploy it to glassfish (tomcat by default uses SE, not EE, however you can set up tomcat to use EE).
If you need tomcat + EE as me (for sake of liferay IDE that doesn't work well with glassfish), check out that project http://tomee.apache.org/downloads.html
Note: I didnt used it yet so i cannot confirm if it works fine with liferay and liferay IDE.

Want to create Java EE project in Java SE eclipse

I have Eclipse Indigo for Java SE and I have Tomcat in Ubuntu. I would like to develop a Java EE application, using Servlet and JSP.
My Eclipse doesn't include Java EE support. Can I add this somehow? If yes, any extra tool or plugin I need to install or download?
Yes. You'll need to use a server like Tomcat to run your application anyway. (Which you have already.) It comes with <tomcat install>/lib/servlet-api.jar. Just include this in your classpath when developing so the code compiles.
Since Tomcat doesn't support the full Java EE spec, it only gives you the Servlet APIs. But that is enough for what you are doing.

Categories