Java – Byte Array to Hex String

Another Quick Reference Code Snippet

StringBuilder tempString = new StringBuilder(2 * bytes.length);
    for (byte b : bytes) {
      tempString.append(“0123456789ABCDEF”.charAt((b & 0xF0) >> 4));
      tempString.append(“0123456789ABCDEF”.charAt((b & 0x0F)));
    return tempString.toString();



Slick2d Game Engine Animation Example

Using the Slick2d game engine there are multiple ways of creating animations.
The following examples will do the same exact thing, but its two different ways of writing it.

import org.newdawn.slick.Animation;
import org.newdawn.slick.SpriteSheet;

Example 1
SpriteSheet runningSS = new SpriteSheet("/path/to/sprite.png", 24, 32);
Animation runningAnimation = new Animation();
runningAnimation.addFrame(runningSS.getSprite(0, 0), 100);
runningAnimation.addFrame(runningSS.getSprite(1, 0), 100);
runningAnimation.addFrame(runningSS.getSprite(2, 0), 100);

runningSS.getSprite(1, 0) is not the pixel value, but the sprite location if the whole image were broken up into cells based on the width and height defined when creating the sprite sheet

Example 2
SpriteSheet runningSS = new SpriteSheet("/path/to/sprite.png", 24, 32);
Animation runningAnimation = new Animation(runningSS, new int[]{0,0,1,0,2,0}, new int[]{100,100,100});

This example is for slick build 274


Run Maven with Ant

Run Maven with Ant

If you have the option to remove Ant from your projects its probably easier to just use maven for most of the build process, but sometimes it requires too much work and time, so this is a quick solution to have your Ant script run maven.

<exec executable="cmd">
<arg value="/c" />
<arg value="mvn package -e -f path/to/pom.xml " />

Maven command to skip tests



Deploy to Local Maven Repository

Deploy Snapshot or release jar to Local Maven Repository

In Settings.xml


In pom.xml


Copy Maven Dependencies to target folder

The following maven xml will retrieve all the maven dependencies and copy them to the target/lib folder.

<plugin><!-- Copy maven dependencies to the lib folder -->

Add external jars to runnable jar’s manifest file using maven

Add external jars to runnable jar MANIFEST.MF file using maven

Also package project as a runnable jar with the specified main class

<plugin><!-- Set Main class and location of jars to add to the manifest classpath -->
            <manifestEntries><!-- Add manifest Classpath entries that aren't managed by maven -->
              <Class-Path>lib/pojoxml-1.0.jar lib/lwjgl.jar lib/jorbis-0.0.15.jar lib/jogg-0.0.7.jar lib/natives-win32.jar lib/slick.jar</Class-Path>

Packaging External Jars with Maven

<plugin><!-- Copy Dependencies - NonMaven Jars -->

If filtering is set to true, Maven will parse the file using the encoding and rewrite it, I have found that his can cause all sorts of issues including class not found errors.