Setting up your enterprise Java environment
watsonx Code Assistant Standard plan
If you're using the Standard plan and want to work with enterprise Java applications, you need to set up your environment for your IDE.
Visual Studio Code setup
Java requirements
The requirements to use watsonx Code Assistant for Enterprise Java Applications in Visual Studio Code are:
Item | Details |
---|---|
Java | Java SE 11 with Java Developer Kit 11, or a later version |
Maven | Use Maven to build your application. If you are using Liberty Tools and the Liberty Maven plug-in to build your app or project, use at least Maven 3.8.6. |
Set environment variables
Set up your environment variables.
JAVA_HOME
Set the JAVA_HOME
environment variable the same way that you do for Maven. Set it to the JDK directory that contains the /bin
directory so that your Java executable file is in the $JAVA_HOME/bin/java
path.
You can set the JAVA_HOME
environment variable to build your application at a different version, for example, Java 11.
PATH
Set the PATH
environment variable to include the mvn
executable file.
- Windows:
mvn.cmd
- macOS:
mvn
If you use the Visual Studio Code terminal to set the environment variables, you need to restart Visual Studio Code to apply the changes.
Determining the Java developer kit
For Visual Studio Code, if you are using the Extension Pack for Java, watsonx Code Assistant determines the Java developer kit to use in this order of precedence:
Order of precedence | Description |
---|---|
1 | Globally-configured Java developer kit for automatic building in the Red Hat extension, which is java.configuration.runtimes in the IDE settings.json file. |
2 | java.jdt.ls.java.home or java.home IDE settings if they are present. |
3 | JDK_HOME system environment variable. |
4 | JAVA_HOME system environment variable. Required if items 1 through 3 aren't set. |
When watsonx Code Assistant for Enterprise Java Applications features are used, such as Java modernization or upgrade, you can verify which Java developer kit is being used:
-
In Visual Studio Code, click View, then click Output.
-
In the Output view, use the drop-down list to select WCA.
-
Check for a message such as
Using the Java developer kit that is defined in <location> to run watsonx Code Assistant components. The path is: <path>
.
Set logging level
To adjust logging for the Visual Studio Code extension:
-
In Visual Studio Code, open the extension settings for watsonx Code Assistant.
-
In Wca: Log level, switch from the default of
INFO
to another setting such asWARN
.
Eclipse IDE setup
Determining the Java installation
For Eclipse, the Java installation is determined in this order:
- The installation that is configured in the project's build path
- The default Java installation for the IDE
For application modernization and upgrade, the automated fixes use the Java developer kit installation that best matches the target Java version that you chose. You need to:
- Install the Java developer kit.
- In the Eclipse IDE settings, open the Java section and add the installation to the Installed JREs.
Maven setup in Eclipse
Make sure to use Maven to build your application.
Maven is required to be set on the PATH.
Set the PATH
environment variable to include the mvn executable file.
Operating system | Executable file |
---|---|
Windows | mvn.cmd |
macOS | mvn |
For macOS operating systems, the environment variables might not be set as expected when you run Eclipse. To fix the problem, you can restart Eclipse by using the Finder tool to right-click your Eclipse application and choose Show Package
Contents. Open the Contents
folder, select MacOS
, and then run Eclipse by clicking the executable code.
How is the pom.xml
file of a Maven project located?
Watsonx Code Assistant uses the aggregator pom.xml
file to build and manage the entire multimodule Maven project. When watsonx Code Assistant attempts to do builds and other Maven-related activity, it uses the multi-module root
(MMR) to locate the aggregator pom.xml
file.
- The MMR first searches the highest level project directory for the aggregator
pom.xml
file. - If the MMR doesn't find the file, it searches the project directory by going from the highest to the next highest directory structure, and so on, until it finds an aggregator
pom.xml
file. - If the MMR again does not find an aggregator
pom.xml
file, it searches the project directory by going from the highest to the next highest directory structure, and so on, until it finds a regularpom.xml
file. A regularpom.xml
file indicates that the Maven project is a single module project instead of a multi-module project.
However, there is an extra restriction. The multimodule project must have one WAR
file or one EAR
file. There can be multiple WAR files if there is a single EAR file. But, if there are multiple WAR files and no EAR
file, then the project is not supported. The reason is so that watsonx Code Assistant can analyze the correct binary and place the Liberty configuration file (server.xml
) in the correct submodule.