Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JarBundler Ant Task for Mac OS X  (Read 2940 times)
0 Members and 1 Guest are viewing this topic.
Offline fletchergames

Senior Member





« Posted 2008-08-08 20:58:46 »

I'm using the JarBundler Ant task from within Eclipse.  A regular Hello World application gets bundled fine.  When I try to bundle an application that contains resource files, it can't seem to find them.

Whenever I use:
    System.getProperty("user.dir")
from within a .app program created with JarBundler, I get a result of "/" no matter what the working directory is set to in the JarBundler task.  The same property when running my program from Eclipse gives me "/Users/StevenF/Documents/eclipse/projects/puzzle carnival/data/", the directory the program happens to be running in.

Here's the relevant part of the Ant build file:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
<jarbundler dir="${release.dir}" name="${app.name}"
   mainclass="${mainclass}" jvmversion="1.5+" shortname="${app.shortname}"
   workingdirectory="./Contents/Resources/"
>
   <jarfileset file="${jar.path}" />
   <jarfileset dir="${vendor.lib.dir}" />
     
   <resourcefileset dir="${data.dir}">
      <exclude name="**/Thumbs.db" />
      <exclude name="**/*.jar" />
      <exclude name="error.log" />
      <exclude name="LuckysPuzzleCarnival.exe" />

      <exclude name="demo license.txt" />
   </resourcefileset>
</jarbundler>


I've tried omitting the working directory and tried changing it to a number of things (including "/Contents/Resources/").  I had assumed that it would just sent the working directory to "/Contents/Resources/" in the first place, but that doesn't seem to be the case.

I've even tried hardcoding the full path "/Users/StevenF/Documents/eclipse/projects/puzzle carnival/data/demo/Lucky's Puzzle Carnival.app/Contents/Resources/" within my code with no success.

I've examined the package contents, and all the files are in the right places.  The .jar files are in the "Contents/Resources/Java" folder, and the resource files are in the "/Contents/Resources/" folder.

Has anyone else had success with this tool?  Does anyone see what I'm doing wrong?  I'm not exactly Mac-savvy, so I might be doing something stupid.  I've had some problems with other .app-generation techniques as well.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2008-08-09 00:11:00 »

Are all your resources in the Eclipse workspace folder? That seems to work for me.

See my work:
OTC Software
Offline fletchergames

Senior Member





« Reply #2 - Posted 2008-08-09 17:17:42 »

Are all your resources in the Eclipse workspace folder? That seems to work for me.
No.  I have them in a separate "projects/Puzzle Carnival" folder.  It runs fine from within Eclipse.

It's just the .app file that I packaged the game in that doesn't work.  The files are stored within the .app package, and I don't know how to get at them.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #3 - Posted 2008-08-09 23:03:06 »

Ah. Well, you can solve your problem by bundling all your resources in a JAR first, then when you put them in the APP you don't have to worry about any Mac OS X specific problems.

Also your problem seems very likely that it is classpath related. I'm guessing that stuff in an APP doesn't use directories, but uses classpath instead. While I'm not sure of this and I've always bundled everything in a JAR before an APP, it might be the problem. Also, when I do need to use directories, I've always just turned the executable JAR into the APP, and then put the resources in the same folder (like a Data folder, like most actual apps do). It's possible that user.dir gives you the directory in which the app rests, rather than its contents.

See my work:
OTC Software
Offline fletchergames

Senior Member





« Reply #4 - Posted 2008-08-11 16:02:16 »

Ah. Well, you can solve your problem by bundling all your resources in a JAR first, then when you put them in the APP you don't have to worry about any Mac OS X specific problems.
I thought of that, but I was hoping that there would be some better solution.  Bundling all the art and music in the JAR file will produce a very large JAR file.

Also your problem seems very likely that it is classpath related. I'm guessing that stuff in an APP doesn't use directories, but uses classpath instead. While I'm not sure of this and I've always bundled everything in a JAR before an APP, it might be the problem. Also, when I do need to use directories, I've always just turned the executable JAR into the APP, and then put the resources in the same folder (like a Data folder, like most actual apps do). It's possible that user.dir gives you the directory in which the app rests, rather than its contents.
I think I'll try contacting the author of Jar Bundler and see what he says about the class path issue.  That has to be the problem, but it should be easily resolved.  I had thought that .app files were basically just folders containing data, but that might not be the case.

"user.dir" just gives me "/".  It's not even the directory of the app.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2008-08-11 21:16:15 »

Try something like this:

1  
BufferedImage bi = ImageIO.read(Thread.getCurrentThread().getContextClassLoader().getResourceAsStream("images/myImage.png");


Typical JAR class loading stuff. See if perhaps the contents folder is part of the classpath.

See my work:
OTC Software
Offline fletchergames

Senior Member





« Reply #6 - Posted 2008-08-12 18:22:58 »

I'll try that tomorrow morning.

I emailed the person listed on the website for Jar Builder, but got one of those mailer daemon emails.
Offline fletchergames

Senior Member





« Reply #7 - Posted 2008-09-03 19:00:37 »

It took me forever (7-day work weeks at my regular job suck), but I finally tried getResourceAsStream.  It didn't work.

It turned out that I had a classpath issue even with double-clicking on the .jar file, but that was easily resolved by changing the manifest file.  The .app file still didn't work after that.

I think I'm going to just distribute the game as a .zip on Mac OS X.  A .app file would be better, but I don't see how I can make it work.

I might try bundling all the files in the .jar file and then making it into a .app file.  It seems like overkill though.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2008-09-05 10:13:32 »

IIRC I had huge problems getting the current versions of Java on OS X to do getResource properly. I have a sneaking suspcion that in the end I gave up and did somehing like detect OS X and use an alternative approach for loading resources. Not very helpful I'm afraid, but I'm pretty sure I ended up with a uniqu Eclipse setup on OS X just to make it work at all.

malloc will be first against the wall when the revolution comes...
Offline fletchergames

Senior Member





« Reply #9 - Posted 2008-09-05 18:57:47 »

It's one of those things that seems like it should work with minimal effort.  And I don't understand enough about Mac OS X or .app files to figure out what's going on.  I tried, but there's only so much effort I'm willing to put into porting this game to Mac OS X.  Even if it could double the number of sales I make, that would probably only be about 3 days pay (at my regular job) per year. Sad

The funny thing is that the game ran just fine on Mac OS X.  All I had to do was change some annotations to match Java 5's rules and stop using a couple of Java 6 constants.  Packaging the game properly is a bit of a mystery though.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #10 - Posted 2008-09-29 04:27:04 »

IIRC I had huge problems getting the current versions of Java on OS X to do getResource properly. I have a sneaking suspcion that in the end I gave up and did somehing like detect OS X and use an alternative approach for loading resources. Not very helpful I'm afraid, but I'm pretty sure I ended up with a uniqu Eclipse setup on OS X just to make it work at all.
I've had no problems with it, although that's not using Jar Bundler, that's just for JNLP on OS X.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!