32

Getting Started With Java EE 8, Java 11, and Eclipse for Enterprise Java and Wil...

 4 years ago
source link: https://www.tuicool.com/articles/bey2ueq
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

If you have been in the Java EE space over the last few years, Eclipse IDE for Java Enterprise Developers is probably one of the best IDE experiences , making the creation of applications with important EE components like CDI, EJB, JPA mappings, configuration files, and good interaction with some of the important application servers (TomEE, WebLogic, Payara, Wildfly, JBoss).

In this line, Red Hat develops the Eclipse variant " CodeReady Studio ," providing you with an IDE that supports Java Enterprise frameworks, Maven, HTML 5, Red Hat Fuse, and OpenShift deployments.

To give support to its IDE, Red Hat also publishes CodeReady plugins as an independent project called JBoss Tools , enabling custom Enterprise Java development environments with Eclipse IDE for Java Enterprise developers, which is what we will demonstrate in this tutorial.

Why? Just for fun. Or, in my case, I don't use the entire toolset from Red Hat.

Requirements

In order to complete this tutorial, you will need to download/install the following elements:

1. Java 11 JDK from Oracle or any OpenJDK distro

2.  Eclipse IDE for Enterprise Java Developers

3.  Wildfly 16

Installing OpenJDK

Since this is an OS/distribution-dependent step, you could follow tutorials for Red Hat's OpenJDK , AdoptOpenJDK , Ubuntu , etc. At this time, Wildfly has Java 11 as a target due to new Java-LTS version scheme .

For MacOS, one convenient way is AdoptOpenJDK tap .

First, you need to install Homebrew :

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After that, and if you want a specific Java version, you should add AdoptOpenJDK tap and install it from there. For instance, if we like an OpenJDK 11 instance, we should type:

brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk11

If all works as expected, you should have a new Java 11 environment running:

java11.png

Eclipse IDE for Enterprise Java Developers

Eclipse offers collections of plugins-denominated Packages; each package is a collection of common plugins aimed for a particular development need . Hence, to simplify the process, you can download Eclipse IDE for Enterprise Java Developers directly.

eclipseenterprise.png

On Mac, you will download a convenient .dmg file that you can drag and drop into the Applications folder .

eclipseinstall.png

The result is a brand new Eclipse installation with Enterprise Java (Jakarta EE) support.

eclipseideee.png

JBoss Tools

To install the "Enterprise Java" features to your Eclipse installation, go to JBoss Tools main website at https://tools.jboss.org/ — you should double check the compatibility with your Eclipse version before installing. Since Eclipse is launching new versions each quarter, the preferred way to install the plugins is by adding the updated URL.

First, go to:

Help > Install New Software… > Work with:

And add the JBoss Tools URL http://download.jboss.org/jbosstools/photon/development/updates/

jbossrepo.png

After that, you should select the individual features, a minimal set of features for developers aiming Jakarta EE is:

  • JBoss Web and Java EE Development: Support for libraries and tools like DeltaSpike, Java EE Batch, Hibernate, JavaScript, JBoss Forge
  • JBoss Application Server Adapters: Support for JBoss, Wildfly and OpenShift 3
  • JBoss Cloud and Container Development Tools: Support for Vagrant, Docker, and Red Hat Containers development kit
  • JBoss Maven support: Integrations between Maven and many EE/JBoss APIs

jbosstools.png

Finally, you should accept licenses and restart your Eclipse installation.

Wildfly 16

Wildfly distributes the application server in zip or tgz files. After getting the link you could do the install process from the CLI. For example, if you wanna create your Wildfly directory at ~/opt/ , you should execute the following commands:

mkdir ~/opt/
cd ~/opt/
wget https://download.jboss.org/wildfly/16.0.0.Final/wildfly-16.0.0.Final.zip
unzip wildfly-16.0.0.Final.zip

It is also convenient to add an administrative user that allows the creation of DataSources , Java Mail destinations, etc. For instance, and again using  ~/opt/ as a basis:

cd ~/opt/wildfly-16.0.0.Final/bin/
./add-user.sh

wildflyadmin.png

The script will ask basic details like username, password, and consideration on cluster environments; in the end, you should have a configured Wildfly instance ready for development. To start the instance, just type:

~/opt/wildfly-16.0.0.Final/bin/standalone.sh

To check your administrative user, go to http://localhost:9990/console/index.html .

wildflydashboard.png

Eclipse and Wildfly

Once you have it all set, it is easy to add Wildfly to your Eclipse installation. Go to servers window and add a new server instance, the wizard is pretty straight forward, so screenshots are added for reference:

wildfly16.png

wildfly16local.png

wildflyhome.png

If you wanna go deep on server's configuration, Eclipse allows you to open the standalone.xml configuration file directly from the IDE, just check if the application server is stopped, otherwhise your configuration changes will be deleted.

standalone.png

Testing the Environment

Check your pom.xml for Java 11 capabilities, specifically Maven compiler source configuration. The complete pom.xml file should be similar to this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.nabenik</groupId>
    <artifactId>eetest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>eetest</finalName>
    </build>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
</project>

Since the IDE and application server are compatible with Java 11, it is possible to use local type inference in JAX-RS.

To test this application, I've created a nano-application using an Archetype for Java EE 8. The application server and IDE support Java 11, and the deployment works as expected directly from the IDE.

java11ee.png

And there you have it! Hope you enjoyed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK