I spent some time today trying to get Slick and the light-weight java game library setup correctly in Eclipse. The tutorial I was watching was in Netbeans and I was very unfamiliar with adding libraries to a Java project in Eclipse (very familiar now). I’m going to go over how to do this as an overview, mainly just to remind me how to do it later hehe. It may also be of use to others who don’t need a step by step picture guide of the process. So, here goes!
- Create a new project in Eclipse
- Right-click the project and choose New -> Folder (call it “lib”)
- Right-click the lib folder and choose Import… then General -> File System
- Browse to your slick folder and choose the slick.jar and the lwjgl.jar files.
- Right-click on the project and choose Properties
- Choose “Java Build Path” and click the “Libraries” tab
- Click “Add Jars”. It will show a tree of your project. Expand it till you see your lib folder. Expand it. Select the two jars (utilize shift for multiple selection). Click OK.
- Click OK again to go out to the workspace.
- Right-click on the lib folder and Import again. This time use “Archive File” instead of “File System”. Click Next.
- Browse to your slick lib folder and find “natives-win32.jar”. Click open.
- It will list some dlls on the right column. Make sure they are all checked and click finish.
- Repeat steps 9-11 and add the natives for mac and linux the same way if you want them.
- Now you need to add those natives to lwjgl. So…
- Right-click on the project and choose properties.
- In the Java Build Path -> Libraries tab, expand lwjgw.jar and click on Native library location.
- Click Edit. Click Workspace. Navigate to the lib folder, choose it, and click OK.
- NOW ALMOST THERE!
- Back in the Java Build Path -> Libraries, expand slick.jar. Click JavaDoc location.
- Click Edit. Set the javadoc location path to the location of the slick\javadoc folder.
Step 20… Add a class to your project and see if it will compile correctly. Here’s an example for testing.
GameTest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import org.newdawn.slick.AppGameContainer; import org.newdawn.slick.BasicGame; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.SlickException; public class Game extends BasicGame { public Game(String title) { super(title); } public static void main(String[] args) throws SlickException { AppGameContainer app = new AppGameContainer(new Game("Test Game")); app.start(); } @Override public void render(GameContainer container, Graphics g) throws SlickException { g.drawString("Hello, World!", 0, 100); } @Override public void init(GameContainer container) throws SlickException { } @Override public void update(GameContainer container, int delta) throws SlickException { } } |
Thank you for the amazing tutorial! 😀
Very concise, got me right back into slick, thanks!