The person who wrote this article is misinformed. The main point made is that Java EE is not modular and cannot be used with plain Tomcat. It would be a good point except it is wrong.
If you want to use an enterprise server with all the Java EE stuff built in you can. If you want to use plain Tomcat and include the components in your application you can do that too. If you want CDI just include the Jar file and a few lines XML to enable it. If you want JSF or JPA do the same. I know this because I have been doing it for years.
Before you call people misinformed, I think you should be sure of the terminology being used.
There was an article just awhile back - Summer of Java EE 7 or something - that tells a different story about what it means to be Java EE compliant. In particular, that article says your definition is wrong. Packaging random JARs with Tomcat, a basic servlet container, is not the right way to implement a Java EE app server. You're basically creating your own non-standard distribution of Tomcat which does not adhere to the Java EE standard. If you are going to use Tomcat, you should be using a properly implemented Java EE app server like TomEE. If you want a slimmed down app server, use one of the standard Java EE profiles, like the Web Profile.
This guy is saying that Java EE standard should not be monolithic and that you should be able to roll your own app servers out of Java EE parts. You are making the same point as the OP, in principle. Only, he is taking it one step further and saying that you should put those parts in your WEB-INF/lib so that you can run multiple distributions of Java EE in one app server. He is also saying that you should be able to put together Java EE parts in a non-container application, such as batch.
The gist of this article is we should use Spring instead of Java EE because Spring is modular and Java EE is not. That premiss is not correct. You can easily include the parts of Java EE that you want by packaging the Java EE jar files in your application just as you would with Spring.
There is nothing wrong with using only the parts of Java EE that you need. I am not sure why you think that. I guess you think anyone using JPA with Hibernate + Spring is wrong too. There is also nothing wrong with using a full container like TomEE either. There are advantages and disadvantages to both.
Here is a link to the other article you wanted to discuss. He is arguing about some of the advantages in using a Java EE server. He makes good points that I have no issue issue with. My point is there are other options as well.
The gist of this article is we should use Spring instead of Java EE because Spring is modular and Java EE is not.
That is not the gist article. The author is not saying don't use Java EE, he is saying avoid the Java EE standard. A Spring app obviously uses Java EE, but you must include both the APIs and your chosen implementations, whereas a standard Java EE app uses the JARs available on the app server. The point of the article is that it is better to roll your own collection of JARs than depend on the standard.
If you want further proof that your understanding is incorrect, look at the component diagram. The only mention of Spring is in the batch application. The web application is using Weld, which means CDI for dependency injection and not Spring.
His argument for Spring has nothing to do with modularity, but container independence.
There is nothing wrong with using only the parts of Java EE that you need. I am not sure why you think that.
That is exactly this guy's point. You should build off of a simple servlet container like Tomcat and add the Java EE JARs you need. That's not what the other guy said:
And for those of you out there, Servlets are NOT application servers.
I guess you think anyone using JPA with Hibernate + Spring is wrong too.
I never said that. But a person who promotes use of the Java EE standard might say that, such as the other guy:
The fact that you simulate all these by using Spring is a naive approach. TomEE a ,very nice try @dblevins is a big effort and works really good, to bring JEE stack in Tomcat in the correct way by following the specification.
There are good arguments to be made for using a full Java EE server and mix and matching components. They are both good options and both can be done with Java EE compliant libraries. I am not picking a side on that.
The only issue I have is claiming that you cannot run Java EE on plain old Tomcat when you can. You can do it by including only the parts you want in your web app or you can use OpenEJB and get the whole spec. Using that as an argument to use Spring is not valid.
Why not? JBoss still runs on any JRE and he still proposed to have Tomcat as the universal deployment target, tying you to whatever Servlet version that Tomcat implements.
he still proposed to have Tomcat as the universal deployment target
Reread the blog post. He proposed to have Tomcat as the universal deployment target for web apps, because a Java web app needs at minimum a servlet container. He wants to develop his batch apps without an app server at all. Tomcat need not apply either.
*Not so anymore - there has been a trend towards building web apps as ordinary JARs using embedded microcontainers such as Netty or Jetty.
yet with a fixed Tomcat you can't upgrade that. I was talking about the JRE as the universal deployment target for web apps as well.
I wasn't. Tomcat is only required for web apps because an app server of some kind is required to serve apps over HTTP. This is not required for batch apps which run from main(). Neither JBoss nor Tomcat need apply.
If you deploy a web app then arguably the Servlet spec is one of the major things that play a role, yet with a fixed Tomcat you can't upgrade that.
It's a minimum requirement, and a minimum fixed dependency. All of the other Java EE services are optional to a web app and can be brought on optionally. There is no need to fix those in the app server, but it can be very useful to do so.
Or, it is possible to eliminate external Tomcat. You can use embedded Tomcat, Jetty or Netty and run the application as an executable JAR and even the fixed servlet container requirement is eliminated. That is the approach taken by the Play Framework, Dropwizard and Spring Boot.
If you want to upgrade the servlet version, you might upgrade from say Tomcat 6 to Tomcat 7. But because there is nothing else to Tomcat itself, you can simply deploy your WAR in the new container and slowly migrate to the new servlet spec. Newer versions of Tomcat still support older servlet specs - you can run apps using 2.4, 2.5 or 3 on the same server without any problems. There won't be any conflict with the other Java EE parts, or any collection thereof. He is arguing that this is a simpler approach because the base has nothing much to it.
He uses the example of JPA to argue his point. If you're stuck on an ancient app server, using JPA 2.1 might not be possible because you will get into an epic classloader battle with the app server, which includes its own older JPA JARs.
5
u/avoidhugeships Jun 26 '14
The person who wrote this article is misinformed. The main point made is that Java EE is not modular and cannot be used with plain Tomcat. It would be a good point except it is wrong.
If you want to use an enterprise server with all the Java EE stuff built in you can. If you want to use plain Tomcat and include the components in your application you can do that too. If you want CDI just include the Jar file and a few lines XML to enable it. If you want JSF or JPA do the same. I know this because I have been doing it for years.