Slick Forums
http://slick.ninjacave.com/forum/

FIXED : [ant] [TiledMap] [resource] tiled map not loaded
http://slick.ninjacave.com/forum/viewtopic.php?f=3&t=8443
Page 1 of 1

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

Hello,

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)
Code:
<target name="compile">
      <mkdir dir="${bin.dir}"/>
      <javac srcdir="${src.dir}" destdir="${bin.dir}">
         <classpath>
            <fileset dir="${lib.dir}">
               <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${resources.dir}">
            </fileset>
         </classpath>
      </javac>
   </target>
   <target name="jar" depends="compile">
      <mkdir dir="${jar.dir}"/>
      <mkdir dir=""/>
      <jar destfile="${jar.dir}/${jar.name}" basedir="${bin.dir}">
         <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
         <fileset dir="${resources.dir}" />
         <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
         </manifest>
      </jar>
   </target>


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

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



The error: (useful parts)
Code:
[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(ResourceLoader.java:69)
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
     [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(AppGameContainer.java:393)
     [java]     at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
     [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:
Quote:
URL res = getClass().getResource("/maps/main.tmx");


Could you try to load the TileMap directly? Like

Code:
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

Indeed!

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
http://www.phpbb.com/