My Java Development Setup
The Java sources for TAJ are currently provided without a standard way to build. As a non Java expert I
struggled to get started with debugging or building the software. Sharing what I did may help others -
I don't claim this it is good enough for production but it helped me running the Java debugger and understanding some behavior of TAJ.
While this setup is aimed at
Java development the directory setup is suitable for keeping an eye on your Personality JavaScript code and moving that forward. It is assumed you have basic understanding of how to work on the terminal and install Java on your computer.
On my Mac this is working with
- Mac OSX 10.13
- Java 11
- TAJ 1.0.17/18
Everything should also work on Windows as only platform independent tools were used assuming you have installed GitBash (or know your way around Windows and do some minor adjustments).
In the following I'll describe how to:
- set up the tool-chain
- build the TAJ software
- set up Visual Studio Code to debug the Java code
Why is building so difficult? Is there not a standard way? The issue is that there are many standard ways. There are 3 main ways to build Java software: Ant, Maven and Gradle. In addition there are IDEs which may provide built-in capabilities. Almost last but not least IDEs generate build files that are overly complex and don't hold up so well in other setups. Finally complexity is added by tools and IDEs having opinions about directory layouts.
Just to make life even harder over the past years Java got a module system and it was decided to move JavaFX out of the Java 11 distribution. Which requires TAJ to dynamically download JavaFX when it first starts up and then to restart itself complicating development and debugging setup. Doing this so it works well for others and covers development, testing and distribution is hard so I understand why there is not one yet. I figured I only needed it working for playing around which should be easier so here it goes...
Setting up the tool-chain
Java 11
I downloaded the Java SDK from Oracle but OpenJDK should be fine too. Make sure the following two environment variables are set correctly (Oracle version, otherwise set them in your ~/.bash_profile or wherever you do this).
Code: Select all
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
export JDK_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
Start a fresh shell and check java is there and has the right version with java --version. OpenJdk users may have to adjust their shell's PATH variable.
TAJ
- Download and unzip the TAJ distribution
- Rename the new directory and remove the version and spaces in the directory name. Do this now, not sure how safe it is to do it later.
- Create in Images a "Domme" folder and within it another folder called "1". Place a few pictures into the "1" folder
- Right click on the TeaseAI.jar and lauch it (or from the command line: java -jar TeaseAI.jar)
- Download the update (if offered) and the JavaFX.
- In the Settings->Contacts->"Dom Name" point the "Image Sets Path" to your "Domme" folder and save the settings.
- When you now Start the default personality your pictures should show up.
This is half way, later Maven and Visual Studio Code need to be installed.
Development directory setup
I wanted to have my development directory set up in a way I maximize the sharing with the "normal" TAJ directory. The development happens
in the "DevDir" subdirectory relative to the previously downloaded and at least one run(!) TAJ installation and there are lot of symlinks.
Code: Select all
git clone https://github.com/GodDragoner/TeaseAIJava.git DevDir
cd DevDir
ln -s ../javafx-sdk-11 javafx-sdk-11
ln -s ../Images Images
ln -s ../Videos Videos
ln -s ../Personalities Personalities
ln -s ../TeaseAI.properties TeaseAI.properties
mkdir target
ln -s target/TeaseAi-1.0-SNAPSHOT.jar TeaseAI.jar
- You do not need the build the software in order to debug it. If you want to debug the internet distribution the you could simply do an ln -s ../TeaseAI.jar TeaseAI.jar and use the development directory and debugger setup (below) this way.
Build setup
I decided to use Maven to build the software. It may not be great but it is independent of any IDE and as the POM has been written by me manually it is reasonably understandable (as pom files go). The build file creates a target/TeaseAi-1.0-SNAPSHOT.jar which contains still way too much but it seems to be running and can be debugged which is good enough for me for the time being.
- Download and unzip a recent Maven distribution, I used 3.6.0. Make sure mvn is in your PATH or have set an alias to ...yourplace.../apache-maven-3.6.0/bin/mvn. You should be able to do "mvn --version" in the terminal.
- Maven uses a pom.xml file in the DevDir to build the software. Create the pom.xml file with following content:
- Spoiler: show
-
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<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>me.goddragon</groupId>
<artifactId>TeaseAi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TeaseAi</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>me.goddragon.teaseai.MainApp</mainClass>
</properties>
<organization>
<name>Your Organisation</name>
</organization>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>
</dependencies>
<build>
<!-- Non standard place -->
<sourceDirectory>src</sourceDirectory>
<!-- Non standard place, contains openjfx_OS_...-sdk.zip . TODO Check: Is this actually bundled and required? -->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<!-- Enforce a minimum maven version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>(3.5,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<!-- Copy the fxml files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-swf-files</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="copy fxml files to target">
<copy todir="${project.build.outputDirectory}">
<fileset dir="${project.build.sourceDirectory}">
<include name="**/*.fxml"/>
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- TODO Don't really need the dependencies in the jar just for building. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<includes>
<include>**/*</include>
</includes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>me.goddragon.teaseai.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args} test</commandlineArgs>
<arguments>
<argument>
test
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- Run Maven build with "mvn clean package". The first run may take a while.
- Start the newly build software: java -jar TeaseAi.jar
Some notes on the setup
- We share the JavaFX with the parent directory and use these for running the software
- The JavaFX jars are also downloaded for building (see the dependency section) which may be ok but it is also put into the Jar which blows it up. Still it works. Medium term risk for confusion of versions.
- When starting the software checks for JavaFX. Then it re-launches itself and loads the JavaFX. For this to work the jar has to be named exactly as it is (or renamed via the symlink to the real jar in the target directory).
Debug and IDE setup
I can just see Java developers shiver when I now describe a setup where I use Visual Studio Code for development. Certainly IntelliJ (not free), NetBeans or Eclipse are more appropriate for Java development. I still like VSC especially as it does not come with a lot of pre-conceived ways of doing things or a lot of configuration state. I also believe that it's strengths on the JavaScript side are useful here for an end-to-end experience.
Download and install Visual Studio Code from
https://code.visualstudio.com/Download
Install the following extensions:
- GitLens
- Maven for Java
- Java Extension Pack (contains a number of relevant extensions)
Create the following .vscode/launch.json file:
- Spoiler: show
Code: Select all
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug me.goddragon.teaseai.Main (javafx passed)",
"request": "launch",
"mainClass": "me.goddragon.teaseai.Main",
"projectName": "TeaseAi",
"stopOnEntry": true,
"sourcePaths": ["src"],
"args": ["--module-path=./javafx-sdk-11/lib", "--add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.media,javafx.graphics,javafx.swing,javafx.web", "test"],
}
]
}
- With "File->Open..." (not Open Workspace) select the DevDir and press "Open". You may get some prompt asking about the visibility of your .vscode directory, I suggest to keep it visible.
- The software can now be debugged simply by going "Debug->Start debugging". You will get an error but you choose to proceed anyways. We are building the software not with VSC and don't care what VSC thinks here.
- The VSC launch.json starts already the second phase of the bootstrapping process you are are now in a position to set breakpoints and examine the behavior of the software as you please
.