Search code examples
eclipsejakarta-eejboss

Maven and EJB (JEE)


I am new to the language JEE and I didn't find my answer anywhere. Can someone please tell me while creating a project on Eclipse or JBoss Studio what is the difference between choosing a Maven project or an EJB project? Thank you for taking the time to answer.


Solution

  • First of all JEE is not a language it is the enterprise platform of Java, which holds a bundle of specifications such as JPA, EJB, JAX-RS and so on. Application servers which are certified as a JEE Server provide all of the JEE API and implementations and can run your JEE-Applications.

    https://docs.oracle.com/javaee/6/firstcup/doc/gkhoy.html

    A Maven Project is a Java Project based on the build tool maven, and the EJB Project is a IDE specific configuration, whereby the configuration is specific to the IDE and is not portable to other IDEs. With Maven and the use of the maven-ejb-plugin the IDE is capable of configuring itself to provide all the tooling you need for EJB development.

    The recommendation is to always manage your Java Projects with build tools like maven, because of the following explained reasons.

    Managing a Java Project with the IDE

    If you manage a Java Project via the IDE without the use of Build Tools then you cannot use the project in another IDE, and you can only build it in the IDE you created and managed it. So the Java Project will not be portable between different IDEs. You will have to define all dependencies yourself even the transitive ones, which are automatically resolved by build tools.

    Managing a Java Project with a Build Tool

    With a build tool you have a Java Project which is managed by the build tool, whereby the build definition is independent from the IDE you use. Also with a build tool the builds of your project can be automated and used in build servers, where you won't have an IDE available. Build Tools are well supported in all IDEs and build servers. All IDEs can import the Java Project and configure themselves with the build tool specific build definition. If you change the build definition you just need to update the project and that's it.

    What are the most common Build Tools in Java?

    The most commons Build-Tools are

    • Ant (obsolete these days but worth mentioning it)
    • Maven
    • Gradle

    https://ant.apache.org/

    https://maven.apache.org/

    https://gradle.org/

    How do dependencies work in Java?

    Java Dependencies build a non-cyclic graph, which means just because you have added one dependency to your project, it doesn't mean that you have all the dependencies available during runtime, because most dependencies have dependencies theirselves. These kind of dependencies are called transitive dependencies.

    What is a transitive dependency?

    A transitive dependency is a dependency your dependency depends on like this.

    your_project -> dep_1 -> dep_2 -> dep_3
    

    So with a IDE specific configuration you will have to manually add dep_1, dep_2 and dep_3 to your dependencies in the IDE specific configuration, because it will not be done for you.

    With a build tool, you only need to add the dependency dep_1 to your build definition because dep_1 will define the dependency to dep_2 in its build definition and so on. You get the picture.

    Useful links

    See the following links for further information.

    What is a build tool?

    https://jrebel.com/rebellabs/ides-vs-build-tools-how-eclipse-intellij-idea-netbeans-users-work-with-maven-ant-sbt-gradle/

    http://www.lihaoyi.com/post/WhatsinaBuildTool.html

    There is much more to tell about build tools and why using it over IDE specific configuration, but the most important ones for me are the portability between IDEs, possibility of automation of the build and the independence of the build definition and the IDE in use.

    Hopefully I could give you an overview of the difference between managing a Java Project with an IDE or a build tool.