nguillaumin / slick2d-maven

Maven distribution of the Slick2D Gava game development library
BSD 3-Clause "New" or "Revised" License
66 stars 36 forks source link

Install fails on OS X #12

Closed cdlm closed 9 years ago

cdlm commented 9 years ago

I'm running into a lot of problems trying to install slick on OS X. This package requires Java 1.7, which is not the default JDK (1.6 is bundled). Moreover LWJGL seems to be incompatible with >1.7, from what I've gathered.

Which platforms are you testing this package on? Travis has some support for OS X testing, maybe this could help?

cdlm commented 9 years ago

Here are a couple changes that seem to fix most problems with Oracle's 1.8.0_31 JDK. I'm not sure how to fix the native library naming (that's the problem I had with LWJGL). When the build fails complaining that it doesn't find the lib, run ./src/main/script/osx-native-name-fix.sh

stefanhendriks commented 9 years ago

I run OS X and have Java 7 installed (not default JDK, but that should not matter) and Maven 3:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

No problems installing whatsoever.

So I am curious about what kind of troubles you're running into. Is it because of Java 8? Because this project I am building is requiring Java 7. So perhaps this has nothing to do with the slick2d-maven project?

cdlm commented 9 years ago

Here's my info:

$ mvn --version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00)
Maven home: /opt/homebrew/Cellar/maven/3.2.5/libexec
Java version: 1.8.0_31, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

I have no clue how to debug that further… I'd like to, but the whole maven process feels so alien, I really don't know what makes sense to try.

Current state is the slick-maven project goes through mvn install without errors, and I can generate a new project from the archetype by passing -DarchetypeCatalog=local and -DarchetypeVersion=1.0.2-SNAPSHOT, but it persists not finding liblwjgl.jnilib. Renaming that lib to .dylib made mvn test pass, but it's not included in the installed files, so the game I generated out of the archetype does not launch.

cdlm commented 9 years ago

My bad, it does launch from a terminal, provided I mvn package and go fish the game.sh hidden in there as target/platformer-0.0.1-SNAPSHOT-release/platformer-0.0.1-SNAPSHOT/game.sh (and of course IDEA has no idea about this shell script)

For instance, I'd expect java -jar target/platformer-0.0.1-SNAPSHOT.jar to work, but it says Error: Could not find or load main class telecom.uvinfo.game.platformer.Game, even though it's in there:

$ jar tf target/platformer-0.0.1-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
platformer-art-pixel-redux/
telecom/
telecom/uvinfo/
telecom/uvinfo/game/
telecom/uvinfo/game/platformer/
platformer-art-pixel-redux/backgrounds.png
platformer-art-pixel-redux/license.txt
platformer-art-pixel-redux/sample.png
platformer-art-pixel-redux/spritesheet.png
telecom/uvinfo/game/platformer/Game.class
tilemap.tmx
META-INF/maven/
META-INF/maven/telecom.uvinfo.game/
META-INF/maven/telecom.uvinfo.game/platformer/
META-INF/maven/telecom.uvinfo.game/platformer/pom.xml
META-INF/maven/telecom.uvinfo.game/platformer/pom.properties
stefanhendriks commented 9 years ago

I never tried to run the game from the jar itself (yet). I did try to run game.sh and it worked out of the box. Which basically does:

java -jar -Djava.library.path="$BASE/lib/" "$BASE/d2tm-0.0.1-SNAPSHOT.jar"

It runs from my main dir, but also from a higher dir.

How does that run for you?

I wonder if you face the same problems with my project? You can try it out, its hosted at https://github.com/stefanhendriks/dune2themaker4j

stefanhendriks commented 9 years ago

Judging from the error message you post it looks like your JAR is just not created properly. I don't know why but it might have to do with the maven-jar-plugin and/or maven-assembly-plugin.

Perhaps you can try pieces from the pom.xml in my project and see if there are any differences, and if so if they work for you (if my project works for you out of the box).

nguillaumin commented 9 years ago

Hi,

There is a lot going on on this pull request so I suggest splitting it a bit. Would you be able to create a separate one for the Javadoc stuff (file moves and -Xdoclint:none), I'd be happy to merge those. Let's focus on the Mac / Java 8 issues on this one.

I personally test on Linux and Windows with Java 1.7, and I'm using Jenkins for CI. I wouldn't mind using Travis but the testing is a bit complicated on this project as it cannot be headless (it needs a framebuffer to get an OpenGL context) so most of the hosted CIs won't work (I had to install Xvfb on mine to make it work if I recall correctly).

It's also tested with Eclipse but not IntelliJ. One thing to be aware of is that you need to pass the system property java.libary.path to point to the folder containing the LWJGL binaries. So you probalby needs to configure IntelliJ to pass this system property. On Eclipse it works because we use a special plugin which does that for us. That's probably where the Could not find or load main class message is coming from, your Java class is present but it cannot link to the native library at runtime.

I'm not sure about the native libraries suffix i.e. .dylib vs .jnilib. From what I could find online it seems it depends on the Mac OS version (.jnilib before MacOS 10.6, then .dylib for more recent versions).

So I'd suggest first to try to get it to work completely on Java 1.7 in order to not have too many variables.

nguillaumin commented 9 years ago

Just tested with:

Apache Maven 3.0.3 (r1075438; 2011-03-01 04:31:09+1100)
Maven home: /usr/share/maven
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"

...followed the quickstart from the README and it worked fine (running game.sh starts the game). The LWJGL libraries seem to have the .jnilib extension.

A precision perhaps: You don't need to clone this project to use it, because it's distributed in the Maven repos. You just need to follow the quickstart to generate a project from scratch from the archetype.

cdlm commented 9 years ago

I got it to work last night. The jar includes a classpath that expects libraries in a lib/ directory, so it could not find them in target/natives; so, just counter-productive defaults and me being confused by all the duplicated files copies maven keeps around. Tweaking the pom and assembly xml files helped a little, I also added a mvn exec:exec section to launch the game.

About the .dylib vs .jnilib issue, I believe I just copied the file in my maven repo.

As I mentioned, I know nothing about maven conventions. I know I rant and mumble a lot, but it just seems strange that after a build I get 2 copies of the native libraries, 2 of the game jar, a copy of the dependency jars, and again all of this in a zip. I expected mvn compile to organize its result files so that the code can be invoked without re-specifying the whole option/classpath explicitly. Going fishing for game.sh deep into a version-dependent hierarchy (or worse, inside ~/.m2) does not cut it. I'm used to the Ruby toolchain where it would be something like rake run or just ./bin/game.

About changes to this repo per se, I intend to submit little fixes to Slick (for instance, the SpriteSheet constructor is missing overloads, e.g. specifying margin and image as a path). I'll split this PR as requested.

cdlm commented 9 years ago

Okay, I confirm that following the quickstart to create a game from the archetype works (so with 1.0.0 of slick2d-core, and no liblwjgl.dylib, just the .jnjlib). I still don't want to cave in to maven, so if you know a way to move or symlink game.sh to a more accessible place with a fixed path, I'm all ears.

However the problem persists when building slick-maven… looks like some test really wants the lib to be named .dylib:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@47089e5f
Mon Feb 16 18:09:06 CET 2015 INFO:Initialising sounds..
Tests run: 11, Failures: 2, Errors: 0, Skipped: 5, Time elapsed: 1.181 sec <<< FAILURE!
createDisplay(org.newdawn.slick.ImageTest)  Time elapsed: 0.928 sec  <<< FAILURE!
java.lang.UnsatisfiedLinkError: Can't load library: /Users/damien/Documents/Scratch/slick/slick2d-maven/slick2d-core/./target/natives/liblwjgl.dylib
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
- - - - - snip >8 snip - - - - -
nguillaumin commented 9 years ago

The idea with the packaging was more about distributing the game rather than using the package during development. For development I'd recommend just importing the project in your IDE and running it from there. I never use game.sh myself, and similarly the packaged JAR with its lib/ classpath is intended for distribution, it's impractical for development.

That's for the same reason that you'll get 2 copies of everything. One in target/ because that's where Maven put things and where your IDE will find them, and another one under the package folder needed to ZIP and package everything with the proper classpath and all.

In any case an exec goal sounds like a good idea so I'd happily take a pull request for that ;) if you can modify the archetype to include it.

I reproduced the problem when trying to build slick2d-core on Mac OS, I'll see what I can do...

nguillaumin commented 9 years ago

I just pushed a new commit which bumps LWJGL to the latest version and that seemed to fix the Mac build. I believe the root cause was fixed in LWJGL 2.9.2 according to their changelog:

2014-11-28  Ioannis Tsakpinis <iotsakp@gmail.com>

    * src/java/org/lwjgl/LWJGLUtil.java, src/java/org/lwjgl/Sys.java,
    src/java/org/lwjgl/util/applet/AppletLoader.java: Replace .jnilib
    with .dylib on OS X with JDK 6. Resolve #100
stefanhendriks commented 9 years ago

Nice catch @nguillaumin . So when does/did this issue occur? Because I can create a package just fine (and developer from my IDE).

nguillaumin commented 9 years ago

It happens when you try to build slick2d-core. Not sure why it doesn't happen with actual games though since they use the same library loading system, but I'm not especially keen on spending the time to investigate ;)

stefanhendriks commented 9 years ago

ah that makes sense. I can imagine you don't want to investigate why it works for games ;-)

Glad to see activity on this project! :+1: