IntelliJ Dependencies - Difference between Specifications und Implementations - java

When starting a new JavaEE Project in IntelliJ you are prompted to include either Implementations or Specifications in your project. Can anyone explain whats the difference here, lets say in context to Hibernate/JPA

Usually, if you develop with a full featured Java/Jakarta EE application server, like GlassFish you only need to add dependency on specification JARs and the application server will provide their implementations.
Different application servers provide different set of supported Java EE standards. For instance, GlassFish provides almost everything while Tomcat provides servlet-api and websocket-api and that's it.
If you choose more lightweight server, like Tomcat, to develop and deploy you should choose Java EE libraries (implementations) because Tomcat will not provide you JPA or JMS library.
Full list of Jakarta specifications (APIs): https://jakarta.ee/specifications/

Related

Start Java EE project after standard java

My task is to make a small a project for start my ee studies. Till now, I learned standard java, but i don't get what ee means exactly, how my project would be an enterprise stuff. Has it a different syntax or different setup in IDE? I know it's not a clever question, but I really don't know where to start. Do you have any idea for start a project?
Java EE is no different language or has no different syntax than Java SE. It's built on top of Java SE and comprises a set of standardized APIs and libraries that are helpful for solving problems in an enterprise context.
To name a few:
Web Applications (Servlets, JSPs, JSF, WAR-packaging)
RESTful- and WebServices (Jax-RS, Jax-WS)
Persistence (EJB, JPA)
Context Dependency Injection (CDI)
Security
Batch
Messaging
...
Further it defines a runtime environment - an Application Server - to run enterprise applications. Nevertheless, the classic application server model has become somewhat obsolet, nowadays you either run a single application in an application server or use only parts of the libraries and APIs and embedd those in your applications.
So basically, all you need is an IDE and the libraries. When you're using maven as build environment, all you need is the java-ee maven dependency, see Maven Central
Usually you don't need to know all the libraries and APIs of Java EE in detail, it's good to know what is available out-of-the-box (so you don't reinvent the wheel), but you hardly will need all of them in all of your projects.
I personally avoid JSF, hardly have to deal with JPA, only occasionally do something with Batch or EJBs. More common are CDI, Restful or WebServices and WebApps, and usually a bit of Security.
And a good example for a Java EE Projects, a simple one with some typical use cases and very little code is Adam Bien's Guestbook2.0, which only requires Docker to run.

Tomcat API vs other APIs

I've been learning Tomcat and servlets recently. Now I came to realise that the Oracle API and the Tomcat API are at least somewhat different. I know the Oracle API should be wider, but still even in the limits of Tomcat operation, they seem to have completely different packages, etc.
This may seem silly, but I can't find any answer. Could someone please explain the differences? And in practical terms, if I build a service that runs under Tomcat, will it also run in, say, Glassfish, without any refactoring of imports?
--- EDIT ---
So, apparently I mistook Tomcat API for Servlet API, etc.
The solution is not to look at the Tomcat Javadocs in the shot above, but at Servlet Javadoc, or whatever is in question. The list in the pic can be found at Apache Tomcat 8 Documentation Index, on the left, slightly down.
Thanks, Andreas and EJP.
Java Enterprise Edition
What you call the “Oracle API” is actually the Java Enterprise Edition (Jave EE) specification. I suggest you avoid using your misnomer.
Java EE is a vast collection of dozens of varied technologies layered on top of Java Standard Edition (Java SE). Various implementations of Java EE support different pieces, not necessarily all of them.
Subsets of technologies
The Apache Tomcat project, and similarly the Eclipse Jetty project and others, intentionally implement only these technologies:
Java Servlet
JavaServer Pages (JSP)
Java Expression Language
Java WebSocket
These few APIs are just a small, but vital, subset of Java EE.
The Tomcat API you linked is specific to Tomcat’s implementation. Developers would only very rarely go through that API. Instead we stick to the interfaces published in Servlet, JSP, EL, and WebSocket specifications all published as JSRs. Sticking to the specs means your web app can be deployed on other implementations as an alternative to Tomcat should the need ever arise.
Web Profile
The Java EE Web Profile is a specification that includes Servlet and JSP APIs along with several more, but still a subset of all the possible Java EE technologies. Apache TomEE is one implementation of the Web Profile, that starts with Tomcat and adds more libraries. Another example is Glassfish, which is/was available in either a complete Java EE edition or a stripped-down Web Profile edition. See the Question, What is different about the Java EE packages? (SDK/normal vs Web Profile).
“Full” implementations
Some products implement all (or nearly so) of the Java EE specifications.
Sometimes this is described as a "full" implementation. I consider that label misleading as it implies the subset implementations are missing or lacking something needed. Quite the opposite. You should always use the leanest implementation that includes only the parts you need. More heavily laden servers take more memory, start and stop more slowly, and may cost more money. For example, I build and deploy highly interactive desktop-style web apps using only Apache Tomcat 8 with Vaadin 7 on top of Java 8 Standard Edition (SE) on Mac OS X.
Also keep in mind that many of the Java EE technologies can standalone, separate from a full Java EE implementation. So you can start with a leaner implementation and then add the libraries for just the few individual technologies you need. For example, Bean Validation can be used on Tomcat by adding the JAR file of an implementation.

Which Jersey dependency should I use?

I am trying to set up Jersey with JAX-RS for my RESTful web application but I am overwhelmed by the amount of options.
I'm currently working in Eclipse and deploying to an Apache Tomcat 7 server. I'm using Maven to manage the project dependencies. I am also very new at this.
The Jersey options are very vague in their descriptions and I'm wondering if someone who has been here before can advise me on which dependency/package I need.
Jersey-Maven Page: https://jersey.java.net/documentation/latest/modules-and-dependencies.html
If you do not have a good reason to use Tomcat, I suggest that you use a fully compliant Java EE container such as Wildfly instead. That way you will have all the Java EE API:s available out of the box, and you will not have to worry about downloading the right version of libraries and so on.

How to deploy java application on different server?

If i want to deploy one application on different servers like Open Source Glassfish or TomEE. How can I achieve that without having to include different libraries for each application server? As an example if would like to use Jersey as the rest framework and eclipselink as the persistence framework i have to make sure both support these frameworks. But in case of TomEE it's shipped with other implementations like OpenJPA.
Is it possible to ship the dependencies only with the project and not in combination of server libraries + project libraries?
What is a good way to achieve server compatibility?
Any information or link which describes a solution or help me understand why it's done this way would be great.
Thanks in advance
This is more of a application server classloading issue and usually all application servers have a provision for a configuration file which you can put in your application and instruct the server to load the libraries included in the web application instead of the one present in application server. For e.g., Weblogic has a weblogic.xml file which is put in WEB-INF of war application and where you can instruct server to prefer the application packaged libraries. For JBoss there is similar configuration file jboss-deployment-structure.xml. This way it is easier to have a self contained application which contains all dependencies even if the server has equivalent libraries. Also you can upgrade to higher version of libraries than supported by application server otherwise you have to resort to all sort of hacks.
Easy solution I can think of is using ant task to create war file for each servers. You can have at most 2-3 servers in reality like tomcat ee, jboss and glasfish. So create 3 ant tasks for each like tomcatWar, jbossWar and glassfishWar and each ant task makes sure required jars are shipped as well in the war. This is more easy and extendable solution, also easy to understand and modify for new requirements.

Difference between J2EE and J2SE project [duplicate]

This question already has answers here:
What's the main difference between Java SE and Java EE? [duplicate]
(11 answers)
Closed 9 years ago.
I have downloaded an open source project from github. it is a maven based project. How can I understand that is the project a J2SE project or a J2EE project? what are the diffrences in structure of these two kind of projects?
A J2EE (known as JEE) project is only different from a J2SE project in the sense that it uses JEE components. A JEE project would make use of one or more of the following components listed here.
J2SE (changed to Java SE) is considered the foundation edition of the Java platform and programming environment in which all other editions are based.
J2SE project is for building standalone applications like swing, applets apps etc
J2EE (changed to Java EE) is the edition of the Java 2 platform targeted at developing multi-tier enterprise applications.
J2EE consists of a set of specifications, APIs and technologies defining enterprise application development. J2EE technology providers expose tools, frameworks and platforms that handle a good deal of the details of enterprise application infrastructure and behavior.
J2EE implementations enjoy all of the features of the Java 2 Standard Edition (J2SE) platform with additional frameworks and libraries added to support distributed/Web development.
Simply you can say that J2SE is standalone program with main method, where as J2EE projects are web apps with web.xml
More info on directory structure here
If we are talking about maven archetypes, it may mean that maven will generate different directories for your source and binary files. Maybe it will package your j2se project as a .jar (kind of a dynamic library), and will package the j2ee project as a .war or an .ear (different containers for web applications inside a j2ee server). You should read carefully your pom.xml in order to be aware of these differences (and know what you actually need for your project).
Please tell me if this has been of any help or if you need any more detailed info...
JAVAEE and JAVASE could be distinguished by the import and container reliability.
For instance: JAVASE seldomly needs javax.ejb package, while JAVAEE need it.
Also, EJB which is core component of JAVAEE application, need container support from web server. like weblogic websphere or jboss.
If you find it rather hard to run it on tomcat, it might possibly a JAVAEE application.

Categories

Resources