This guide is intended for setting up an existing Maven project to create BlueJ compatible project jars.
Alternative build systems:
This is the setup guide for any machine, there is a Linux specific guide below too but I recommend using Powershell since you get more control with less fiddling around.
-
Configure Maven through
pom.xml
to allow it to export jars with dependencies.Add the following to your
plugins
section:<plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <!-- include this section to make it executable --> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <!-- change this to your main class --> <mainClass>uk.insrt.university.bluej.App</mainClass> </manifest> </archive> </configuration> </plugin> <!-- this section is required to export correctly --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <!-- change this to your main class --> <mainClass>uk.insrt.university.bluej.App</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins>
Note: You may already have the
maven-jar-plugin
plugin installed, simply replace it or add the extra configuration as above to make it executable. -
If you haven't already, make sure Maven is in your PATH, verify this by running
mvn
.Refer to Windows prerequisites for instructions. You can download Maven itself here if you haven't already and are just running it through your IDE.
-
Download BlueJ.ps1 and place it in the root of your project.
-
Export your project for BlueJ.
./BlueJ.ps1 -Build
-
If this fails and you are on Windows, you may need to enable script execution.
-
Optionally, open it in BlueJ to print or view class diagram.
./BlueJ.ps1 -Run # You may also include -Build to build before running.
By default,
-Path
is configured for the default Windows installation path, if you are for example on Arch Linux, you should set it as follows:./BlueJ.ps1 -Run -Path bluej
The Powershell script has several parameters you may specify:
Parameter | Type | Description | Default |
---|---|---|---|
Build |
Switch | Set to tell the script to build the BlueJ jar. | false |
Run |
Switch | Set to tell the script to run BlueJ with the jar. | false |
NoClean |
Switch | Will not destroy test directory after closing BlueJ. | false |
BlueJ |
String | Path to BlueJ executable. | C:/Program Files/BlueJ/BlueJ.exe |
TestDirectory |
String | Directory to -Run the project in. | test |
OutFile |
String | Where to export the BlueJ jar. | target/bluej_out.jar |
BuildCommand |
String | Build command to produce jar with dependencies. | mvn clean compile assembly:single |
-
You do not need to do any additional work to configure BlueJ, each time it's imported, BlueJ performs a final conversion and creates the
package.bluej
files that are missing. -
Class diagrams need to be manually created and added to your source files, for example, run
./BlueJ.sh -Run -NoClean
, organise your class diagrams then exit out. Copy over any meaningfulpackage.bluej
files into your source code, these will be bundled as such when you export. -
You do not need to bundle any extra dependencies manually, e.g. adding to the
+jars
folder like in BlueJ, you can simply pull them in through Maven.Dependencies are exported in the JAR alongside your source and classes, BlueJ can discover these just fine and it is unnecessary to include the dependencies twice.
This is the setup guide for Linux machines with Bash.
-
Include plugin in
pom.xml
as stated in the main setup guide. -
Download bluej.sh and place it in the root of your project.
-
Give the file permissions to execute.
chmod +x bluej.sh
-
Export your project for BlueJ.
./bluej.sh build
-
Optionally, open it in BlueJ to print or view class diagram.
./bluej.sh run
You can also chain commands together:
./bluej.sh build run