Java app developed using SCRUM - Delivery helper
Regarding the project's constraints, a good choice is to develop using Eclipse. The following tutorial will teach you how to use basic tools with Eclipse.
Eclipse is an open source IDE for Java's technologies.
To install the last version of eclipse on Ubuntu and derivate, you can use ubuntu-make tool:
umake ide eclipse
You may need to install ubuntu-make first
sudo apt-get install ubuntu-make
You can download the latest version here.
To develop in Java, you'll need a JDK. Having one or more JREs beside a JDK will cause conflicts, so the best way to avoid them is probably to delete all JREs and only keep the JDK. Once done, if you already had Eclipse installed, it probably won't start anymore. You'll then need to follow these steps (assuming you're using Windows; otherwise, just do the equivalent):
-
Find
eclipse.ini
, located somewhere likeC:\users\me\eclipse\java-neon\eclipse\eclipse.ini
. -
Add the following lines (correct the last one with the right path):
-vm C:\Program Files\Java\jdk1.8.0_101\bin\javaw.exe
-
Remove the following path from either from PATH or an existing environment variable:
C:\ProgramData\Oracle\Java\javapath;
-
Add the JDK's bin folder to your PATH (correct the path if needed):
PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_25\bin
-
Start Eclipse
Good news, JUnit is already integrated in Eclipse Neon.1 ! All you have to do is to enable it.
- Go under
Project > Properties > Java Build Path > Add library
and select JUnit. - Add a run configuration based on JUnit to run your tests.
- Congratulations!
CoFoJa mean Contracts for Java. You'll find more information about design by contract here.
Let's explain to you how to use CoFoJa using an example.
-
Create a basic console Java project in Eclipse, and add the following main class:
public class Main { public static void main(String[] args) { // Let's see how CoFoJa works System.out.println(squareRoot(-7)); } public static double squareRoot(double number) { return Math.sqrt(number); } }
-
Run it. Of course it will throw a nice error, cause you tried to calcul the square root of -7 (you're probably bad at maths).
But hey, after all, who said you need to be good at maths ? Why people who coded the
Math
library haven't prevented you from doing such an heresy ?That's where CoFoJa comes in.
Here comes the configuration part
-
Download CoFoJa from the official repository.
Be sure to take the latest version, and the one bundled with asm (i.e., the one named cofoja.asm-version.jar).
-
Put in next to your
/src
folder, let's say under/lib
. -
Go under
Project > Properties > Java build path > Libraries > Add external JARs
and add the previously downloaded jar. -
Go under
Project > Properties > Java compiler > Annotation processing > Factory path > Add external JARs
and add the previously dowloaded jar.You'll need to check Enable project specific settings first.
-
Go under
Project > Properties > Java compiler > Annotation processing
and add the following keys - values:com.google.java.contract.classoutput : %PROJECT.DIR%/bin com.google.java.contract.classpath : %PROJECT.DIR%/lib/cofoja.asm-version.jar com.google.java.contract.sourcepath : %PROJECT.DIR%/src
Of course, correct the values with the right ones if needed.
You'll need to check Enable project specific settings first, as well as Enable annotation processing and Enable processing in editor.
-
Then, you can import CoFoJa annotations and add some, so the example class looks like this:
import com.google.java.contract.Requires; public class Main { public static void main(String[] args) { // Let's see how CoFoJa works System.out.println(squareRoot(-7)); } @Requires("number > 0 && a <3") public static double squareRoot(double number) { return Math.sqrt(number); } }
-
Eclipse should now tell you that there's an error with your contract, because a is undefined.
Congratulation, you've successfully added CoFoJa to the Eclipse project!
-
When running, you still see an error, but related to the contract.
Pro tip: if CoFoJa still doesn't work, you can see what's wrong when building / cleaning the project
by showing the error log window: Window > Show View > Error Log
.