Slick Forums

FIXED : [ant] [TiledMap] [resource] tiled map not loaded
Page 1 of 1

Author:  viicky [ Thu Oct 26, 2017 10:36 pm ]
Post subject:  FIXED : [ant] [TiledMap] [resource] tiled map not loaded


I am currently using slick2D to make a small project.

The map loads and displays correctly while using eclipse, but won't load when running a jar file built with ant.

build.xml: (useful parts)
<target name="compile">
      <mkdir dir="${bin.dir}"/>
      <javac srcdir="${src.dir}" destdir="${bin.dir}">
            <fileset dir="${lib.dir}">
               <include name="**/*.jar"/>
            <fileset dir="${resources.dir}">
   <target name="jar" depends="compile">
      <mkdir dir="${jar.dir}"/>
      <mkdir dir=""/>
      <jar destfile="${jar.dir}/${}" basedir="${bin.dir}">
         <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
         <fileset dir="${resources.dir}" />
            <attribute name="Main-Class" value="${main-class}"/>

How I load the map:
//inside one of my classes
URL res = getClass().getResource("/maps/main.tmx");

map = new TiledMap(res.getFile());

The error: (useful parts)
[java] java.lang.RuntimeException: Resource not found: file:/C:/Users/perso/workspace/ACL2017_Tartiflotte/exe/Tartiflotte.jar!/maps/main.tmx
     [java]     at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(
     [java]     at model.Level.loadMap(Unknown Source)
     [java]     at model.Level.<init>(Unknown Source)
     [java]     at model.World.<init>(Unknown Source)
     [java]     at model.Game.<init>(Unknown Source)
     [java]     at model.GameUI.init(Unknown Source)
     [java]     at org.newdawn.slick.AppGameContainer.setup(
     [java]     at org.newdawn.slick.AppGameContainer.start(
     [java]     at model.Main.main(Unknown Source)

I bet the error is easy to handle, something to add to build.xml, but I failed to figure what.

Could you give me a hand with this issue ?
Thanks by advance!

Author:  Stef [ Sun Oct 29, 2017 5:08 pm ]
Post subject:  Re: [ant] [TiledMap] [resource] tiled map not loaded

Hello Viicky,

this is the problem line:
URL res = getClass().getResource("/maps/main.tmx");

Could you try to load the TileMap directly? Like

TiledMap map = new TiledMap("path to tiledmap")

It will use the ResourceLoader internally
You can look at the source to see what it does

Author:  viicky [ Mon Oct 30, 2017 5:58 pm ]
Post subject:  Re: [ant] [TiledMap] [resource] tiled map not loaded


In fact, seeing that my post wastn't there after 2 days, I thought that I forgot to hit the "post" button.
So I tried another forum. And they successfully helpt me.

Sorry for the inconvenience!

How do I specify that this problem is fixed?

Author:  Stef [ Tue Oct 31, 2017 8:15 pm ]
Post subject:  Re: FIXED : [ant] [TiledMap] [resource] tiled map not loaded

Glad to hear that your issue is solved.

You didn't forget to push the post button. It can take 2 days or longer before your post is approved. We had a problem with spammers and since then each post must be manually approved by a moderator that's why..

There is no way to set the issue as resolved :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group