|Simple greenfoot tetris game|
Imagine a situation where you have developed from scratch, a tetris game in greenfoot, and then you said to yourself,
“Hmm, I’m too lazy to write down the score saving code manually, I should use derby instead.“
If you want to utilize derby or any other libraries in greenfoot IDE, the IDE has to know where the derby library is and load the derby library’s driver from there. For that, you need to do:
Set the classpath in greenfoot environment by:
- Clicking edit -> preferences.
- In libraries tab, in user libraries, click add and enter the location to your derby.jar files .
- Finally, restart greenfoot.
Problem with Deployment
While it is relatively easy to use derby to create and access database right away in your greenfoot scenario, it’s not the same if you deploy it into a jar file.
|You see me losing the game..|
But, worry not--remembering the Java packaging/deployment tutorials, I’ve decided to put derby library (jar) in the same directory as the game’s jar file (not inside the jar) and set the classpath in the game’s jar manifest file to include the derby library.
Derby’s database system and your database folder, will belong in the directory (root directory) that contain your game and derby library’s jar files.
|These are the highscore which is saved using derby library|
The final file structure of your distribution more or less should look like this:
[your game directories] /
|--- [your game].jar
To summarize things up, you can use external libraries in greenfoot by addressing the libraries in the preferences. After you deploy your greenfoot scenario into jar file, you should put the library besides your scenario jar’s file (or database folder) and tell your game’s jar file manifest where the library is.
Tetris game: https://drive.google.com/file/d/0B27ziWaCDimLenNKNkZVYWNwdms/view?usp=sharing