-1

I'm currently working on a simple RPG game with me and my friend in Java. One of the things I'm doing is drawing a tile-based map via .txt files, this way I can easily store and edit maps. Currently I'm loading maps like this:

enter image description here

And here is how the project is currently organized:

enter image description here

My question is, in Netbeans, how do I setup compiling so that when I do a clean compile, it automatically includes the .txt files in the right path so I can just send a .jar to a friend who wants to play? (Or send a .zip containing the .jar, and the /Maps/map1.txt files) Any solutions are helpful, thanks guys!

Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71
  • 2
    Two ways. You can modify the `build.xml` on the `-post-jar` target or you could maintain the file as a bundled resource (within the jar) – MadProgrammer Jun 19 '13 at 06:22
  • jars are zips, btw. Not much use in zipping a jar. – scottb Jun 19 '13 at 06:23
  • How does one perform the former? I've never fiddled with the build.xml and have no idea where to start with that. – user2467047 Jun 19 '13 at 06:37
  • For deploying Java desktop apps., the best option is usually to install the app. using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). JWS works on Windows, OS X & *nix. – Andrew Thompson Jun 19 '13 at 12:18
  • I used [this answer](http://stackoverflow.com/a/14879968/778118) to accomplish this task successfully last week. – jahroy Jun 20 '13 at 06:58
  • @scottb zipping a jar is common practice - but not for compressing it - just to have one single file to transfer to the users containing the jar, some documentation and/or license files... – mschenk74 Jun 20 '13 at 07:18

1 Answers1

1

As MadProgrammer said, you can edit your build.xml on the -post-jar target. To do this, then you can refer to this link, this link, and this question.

  1. If you have to include libraries as well, try a simple DOS script. Build the java project with Netbeans as usual, then create a directory named 'NewDist' inside NetBeans' project directory and create a file named JarMaker.bat. Here's the script.

    @echo off  
    echo * -------------------------------------------------------- *  
    echo * -      JarMaker V 2.0.0 - For Netbeans Projects        - *  
    echo * -------------------------------------------------------- *  
    echo 1) Creating Temporary Directory  
    mkdir classes  
    echo 2) Copying Library Jars  
    xcopy  /s /y ..\dist\lib\*.jar classes >> nul  
    cd classes  
    echo 3) Deflating Library Jars (this may take a while)  
    for /f %%a IN ('dir /b *.jar') do jar xf %%a >> nul  
    del *.jar >> nul  
    cd ..  
    echo 4) Deflating Main Program Jar  
    xcopy /y ..\dist\*.jar classes >> nul  
    cd classes  
    for /f %%a IN ('dir /b *.jar') do jar xf %%a >> nul  
    del *.jar >> nul  
    echo 5) Creating Unique Jar (this may take a while)  
    jar cvfm ../dist.jar META-INF/manifest.mf ./ >> nul  
    for /f %%a IN ('dir /b ..\..\dist\*.jar') do ren ..\dist.jar %%a >> nul  
    cd ..  
    echo 6) Removing Temporary Files  
    rmdir /s /q classes >> nul  
    echo * -------------------------------------------------------- *  
    echo * -         JarMaker V 2.0.0 - Process Complete          - *  
    echo * -------------------------------------------------------- *  
    

Source

Instead if you want to include images, take a look at this question.

Community
  • 1
  • 1
Federico
  • 521
  • 5
  • 13