Learning JEE

Introduction

I’ll try to keep this short and sweet, so, basically, I’ve just got myself a job where I’m using Java for our back end language, so far I’ve just been learning on the job and I’ve been learning a few bits and pieces in my own time.

I’m currently looking into the whole setup of a JEE project, for a test project, I’ve setup a basic web module project (war), and I’m using Tomcat 7. I’m just trying to get to grips with the basics at the moment, I’m hardly trying to master everything instantly, and it’s no lie that the ecosystem for JEE is pretty darn huge.

Requirements

With my test project, I’m looking to have the following setup

  • HQL/Hibernate
  • JAX-RS
  • Roles
    • Roles Allowed
    • Declare Roles
  • MySQL DB

So far I’ve only done JAX-RS because of how incredibly easy that is to set up and I’ve not really had much time to tinker with my test project. I was just wondering how hard/annoying/awkward is it to get the rest of my requirements setup?

I looked a bit into using roles, and it seems that some resources that I’ve found are incredibly in depth and talk deeply about JAAS, whereas for this project I simply want to be able to query a DB, get some user through an entity class. Then use the roles allowed annotation based on that entity class, I should also mention, I’m trying to build a near enough 100% restul web application here, so I do not want to be storing anything within the session, I’m using load balancing techniques for that, so it’s not a problem! :slight_smile:

Finally

All I really want from this test application is to make a basic back end with a bunch of end points that just chucks out some data. I’ve played around with the pom.xml, web.xml file and I’ve looked into the xml files that come into play with the application server of choice too. I’ve seen a very nice way in which you can use the roles annotation with WildFly, there was a block of XML that ran a query and set the allowed role that way… But I can’t remember it off the top of my head, nor can I remember the resource I found it on, in regards to the roles annotation, I was wondering if there’s a way to do it in some Java class rather than through XML…

That’s my only pet hate about the whole JEE game so far is that there’s a lot of XML/XHTML, especially if you use JSP/JSF, although personally I’m going to stay away from JSP/JSF as I want to build a SPA for the front end. :slight_smile:

1 Like

Does it need to be JEE?

You jump into the technology stack/vendors that is notorious for not being nice from productivity point of view because its main focus is to provide scalability, availability, clustering, enterprise management. And as a result is historically (J2EE) near absolute zero of productivity while at the same time providing no scalability, no availability, and nice polygon to investigate clustering issues. And when I write “no …” I simply mean that it requires expert level to not make any mistake that kills scalability/availability/…
JEE tries to realize its goals by implementing “software engineering Enterprise Patterns”

Historically it is also standard that large institutions are very found of. Because they can buy support form IBM/Oracle/BEA Enterprise Server and think that this will protect their systems from failures, up to the point that they have no more budget to actually have admins that are aware that copy of an server/databese instance on the same physical hard drive is by no means any form of backup (real life situation :smiley: ).

And JEE/J2EE historically really liked XML (this is actually a pattern of separating configuration from code), the same goes for Spring.

That said, there are some components in JEE that are usefull. And actually now JEE is closer to Spring than in the past (J2EE). But the very truth is that every JEE real improvements over the years in day-to-day programming either comes directly from actual opensource frameworks (e.g. Hibernate) or indirectly is inspired by also opensource frameworks (the same, and many others). However every such improvement is always a compromise (to some degree), so the every top level JEE vendors will be happy (e.g. no one will abandon their precious framework in favor of someones else framework). In practice I never really heard “yes we use only JEE standard features and we support all JEE vendor servers” except in projects that just simply use Servlet Container (e.g. Tomcat) and have everything implemented via Spring (and/or other opensource framneworks/libraries) and independently embedded framework for persistence.

The last “innovation” I remember that was invented by JEE/J2EE was: JSF… and I do not want talk more about it.

You might be better with keeping Tomcat as a Servlet Container and go with Spring, or even Spring Boot.
Or ditch Tomcat all together and go directly with Spring Boot (that you ca actually initiate servlet container from within if more than REST endpoints are needed).

I think JEE only vs Spring only, Spring is better to enter the “enterprise applications” word. Mainly because the “standard way” is always limited by standard, and sooner or later you will use that specific vendor feature. First one… then another. And once you know one it will be easier to switch between (JEE vs Spring).

But in the end, nowadays it might not matter much for most applications if you will go JEE or for example Spring. And most differences might matter only in business specific cases or characteristics of the specific project. And most importantly you are Java backend developer if you go with either way.

1 Like

Unfortunately, yes… :joy: … I mean I love actually the development using JEE, it’s just the configuration that I suck at… :stuck_out_tongue:

I’ve discovered this already, the way in which you can execute jersey code using simple to read annotations, I personally find that to be a freaking beautiful feature, and the authorisation implementations too, saves you having to run a function/method to say whether or not the provided user can run the current code or not, etc… I just think it’s such a neat way to do it… :stuck_out_tongue: … Then HQL, that is a pretty darn nice feature too! :slight_smile:

This is something that I’ve also learned very quickly! Including the pom.xml, web.xml and if you’re using JSP, you then have .xhtml files, and you also have the server’s xml files… I’ve very quickly discovered how there’s a tonne of XML included in JEE… :stuck_out_tongue:

Lmao, that’s something I’ve learned VERY quickly… I mean the configuration side of things is a pain… Like in my current role, I’m using a WildFly /7 JBoss setup, but I’m looking to experiment with TomCat, etc… I’ve been made aware the difference between the likes of JBoss and Tomcat, as Tomcat only has basic Serverlet container, as you said and the likes of JBoss has more features that are just ready to go! :stuck_out_tongue:


If anything that’s what I’m working with at the moment, only it’s such a pain and the way in which JSF naturally works, it seems rather messy, I mean I’d rather implement the front end manually, then maybe use some of the back end features that come with JSF, but the fact that it tries to implement a lot of the front end too… Ehhh… I see wy you don’t want to talk more about that! :joy:

I do want to keep it fairly/reasonably simple, I’m not looking to setup anything too complex/sophisticated…

1 Like

I think (I did not revisit standard reference documentation for a long time) HQL is not part of JEE. The JPQL is. But that is a very good example of vendor locking.

As for XML, try always to google for annotation based config example. The XML argument supposedly is being thrown from both opposite groups of fans (Spring and JEE) and in most cases is no longer valid for both technologies.

1 Like

I’ve seen that this is the best way to do it, at least it seems way more common, are you aware of any specific reason(s) as to why it’s the better approach? I’m assuming it’s just a more efficient for the server? I haven’t looked into why Java developers tend to prefer the XML approach, I’m literally taking a shot in the dark right now, I’ll look into it later out of curiosity anyway! :slight_smile:

yyyy… Now I see that my sentence without better context could have different meaning (e.g. JAXB). Since nowadays annotations are used for everything :slight_smile:

I meant that in both cases (Spring and JEE) you can configure everything with XML - if you want to (as a backward compatibility). But most, if not all, things can be also configured with annotations. For example, you can describe in XML that some class will serve as a Servlet (XML aproach). Or you can skip XML and put annotation on that class (e.g. @WebServlet). So whenever you see example that someone used XML look also for annotation solution that usually exists.

As for XML alone… its had some “Enterprise” charm back in a day - and partially still has - in form of XSD and quite complex schema control (deriviation by restriction , deriviation by extention). But now it is more of a burden than charm. But in general XML was everywhere. And JSON do not yet have a schema control that everyone agrees upon.

1 Like

Even though I don’t work for a huge organisation, I can totally see why XML would be pretty damn useful for the configuration.

I mean it probably doesn’t help that I’m used to working on smaller projects, like I’m currently working on making this rather interesting application, I’m pretty much the only developer for the project at hand, I’m currently using PHP and we’re using our own architecture, for the structure of the project I’ve not re-invented the wheel or anything, I’ve just taken that wheel and said :-

“Damn, this is a good wheel, but…”

So I’ve oiled that wheel and added a nice paint job on top! :joy:
I mean with projects like that, it’s kinda nice because you can make your code as scalable as possible, plus using PHP has also helped me learn a tonne about security, especially the numerous flaws that comes with using PHP, it really opened my eyes as to how easy it is to hack into a server if configuration isn’t 100% and/or the code isn’t 100% reliable… I mean I find it hilarious that you CAN implement a shell injection attack through a simple image upload, I genuinely couldn’t believe that! :stuck_out_tongue: … My solution may be a bit over the top, but at least it prevents shell injection or XSS from ever occurring from an image upload feature, so all in all, it’s not too bad! :slight_smile:

1 Like