The following instructions will explain how to set up the suggested build environment on Windows. You will install the Windows Subsystem for Linux with Ubuntu, and VcXsrv to use graphical Linux applications. You will also install the Emacs text editor. For development, you’ll install Java 8, the Gradle build tool, and Error Prone, a tool for identifying possible issues with your code.
- Install VcXsrv, an application which will allow you to use graphical Linux applications on Windows.
- Install Windows Subsystem for Linix (I’ll assume you installed Ubuntu)
- Start your Ubuntu installation and configure your environment by running the below commands (note lines beginning with # are comments):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Set the local display (needed for graphical applications) echo "export DISPLAY=localhost:0.0" >> ~/.bashrc # Update package listings. sudo apt-get update # Install Java 8 sudo apt-get install openjdk-8-jdk-headless # Install Maven sudo apt-get install maven # Install some utilities sudo apt-get install zip unzip # Install SDKMAN, a Software Development Kit Manager tool curl -s "https://get.sdkman.io" | bash |
1 2 3 4 5 |
# Install the Gradle build tool. sdk install gradle 4.4 # Install emacs, a text editor. sudo apt-get install emacs |
1 2 |
#Run emacs emacs |
1 |
C-x, C-f |
1 |
.emacs |
1 2 3 4 |
;;; Add this at the top of the .emacs file: (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) |
Save the file by hitting C-x, C-s. Then, exit emacs (C-x, C-c) and restart it.
Once emacs restarts, type:
1 |
M-x list-packages |
The M-x means “Meta and the x key” where the meta key is usually the Alt key on most keyboards.
A list of packages will be displayed. Scroll down to JDEE and click on it. Choose to install it.
Your build environment is now configured! Let’s test it.
Create a new folder called csc241 in your home directory, and inside that a new folder called testproject. Then navigate into testproject.
1 2 3 4 5 6 7 8 9 |
# Go to your home folder cd ~ # Make some directories mkdir csc241 mkdir csc241/testproject # Change into the csc241/testproject directory cd csc241/testproject |
In emacs, open the (new) file ~/csc241/testproject/build.gradle
This file will contain the configuration for the project.
In your build.gradle, add the following:
1 2 3 4 5 6 7 |
plugins { id "net.ltgt.errorprone" version "0.0.13" } repositories { mavenCentral() } apply plugin: 'java' |
This tells Gradle to use Java to build this project, and to use the Error Prone plugin. Save the file.
Gradle expects to find your source code under src/main/java, so make those directories in the terminal. Then, open the file ~/csc241/testproject/src/main/java/Main.java in emacs.
Create a “hello world” style program in that file and save it.
Back at your terminal, type
1 |
gradle build |
Gradle will then build your project. (Note you can see the other things you can ask Gradle to do by running gradle tasks.)
Now, assuming you had no errors you need to fix, change into the ~/csc241/testproject/build/classes/java/main directory and run
1 |
java Main |
Your program should run.