Skip to content

Setup For Labs

To be prepared for the labs, you'll need the following installed on your machine:

  • Java 11 (or later): ensure it's the one that runs by default on your command line
  • git 2.36 (or later): see the git web site
  • A Java IDE with refactoring capability, e.g., IntelliJ IDEA 2022.2.4 (or later): either the Community or Ultimate Edition
    • or Eclipse

Once everything is installed, you will clone the lab repository to your machine and then run the tests and open it in IntelliJ IDEA.

A. Clone the Repository

Clone the project repository by going to the link provided in class, which will be the GitHub repo. From there you can click on the green CODE button to get the link for cloning.

B. Use Maven to Run the Tests

Failed to execute...

If you see an error like:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project blackjack: Fatal error compiling:
invalid flag: --release -> [Help 1]

Ensure that you have Java 11 or later working from your command-line. Java 8 doesn't understand the --release flag used by later releases.

Do a ./mvnw -v (Mac) or mvnw -v (Windows) to see which version of Java is active when running Maven, you'll see something like:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/foo/.sdkman/candidates/maven/current
Java version: 11.0.11, vendor: AdoptOpenJDK, runtime: /Users/foo/.sdkman/candidates/java/11.0.11.hs-adpt
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

If you see Java version: 1.8... then you'll need to make Java 11 active from the command-line. If you can't figure out how to make that work, skip to Step C below and load it into your IDE.

Once you've cloned (or downloaded) the code, use Maven (./mvnw for Mac, or mvnw for Windows) from the command line to download the project dependencies and run the tests as follows:

Security Error...

If you see a "security" error, you may need to temporarily rename the settings.xml file found in the .m2 directory under your home directory (e.g., ~/.m2 on Mac). Rename it to settings.xml.bak, run Maven, but don't rename it back until you've loaded the project successfully into your IDE.

  1. Change to the directory holding the project

  2. Run the verify task in Maven by doing this from the command-line/terminal:

    Mac/Linux:

    ./mvnw verify
    

    Windows

    mvnw verify
    
  3. Maven will download a number of files, so this could take a few minutes. Once it's finished downloading the files, it will compile the code, run all the tests, and package the project into an executable JAR file. If all goes well, you should eventually see something like:

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.706 s
    [INFO] Finished at: 2020-09-11T10:39:51-07:00
    [INFO] ---------------------------------------------------------------------
    

C. Open Project in IntelliJ IDEA

These instructions are for IntelliJ, if you're using another IDE, open the project via the Maven pom.xml file as appropriate.

Now that all the dependencies have been downloaded, and the project works, let's open it up in IDEA.

  1. Launch IntelliJ IDEA

  2. Open the pom.xml file by doing the following:

  3. If you see the Welcome screen, choose Open (not Import)

Otherwise...

  • From the File menu, choose the Open... to open the pom.xml (don't use Import) in the project directory.

  • IDEA will then ask you how to open this file. Since we want it to be a new project, click Open as Project.

  1. The project will load and IDEA will do some indexing, which may take a few minutes.

D. Run the Tests in IDEA

  1. Once the indexing completes, open the Project tool window (left-side) and right-click on the src > test > java directory and select Run All Tests.

  2. The test results will show up in a bottom window pane and should be green, i.e., all the tests passed.

E. Move on to Lab 1

Once you're done getting the code downloaded and loaded into your IDE, move on to Lab 1.

Other Errors

The error below indicates that your machine is trying to get dependencies, plug-ins, or project information from your corporate Maven repository (aka Nexus or Artifactory), but it's not available. See the solution for "Security Error..." above.

[ERROR] Plugin org.apache.maven.plugins:maven-shade-plugin:3.3.0
 or one of its dependencies could not be resolved:
 Failed to read artifact descriptor for
 org.apache.maven.plugins:maven-shade-plugin:jar:3.3.0:
 Could not transfer artifact org.apache.maven.plugins:maven-shade-plugin:pom:3.3.0
 from/to central (https://nexus...): nexus...:
 nodename nor servname provided, or not known:
 Unknown host nexus...:
 nodename nor servname provided, or not known -> [Help 1]