btw this is exactly like my first experience with jarSplice, which is why it sucks imo.
you should never have to pack resources in the source folder, or pack everything into a fat jar
some of you might prefer that but I think its ugly as hell.
in the end I wanna have one exe that is like 100 kb and an assets folder or pack
so yeah jarsplice is very picky about the resources and stuff.
I havent tried packr. I do own JET which worked fine. Usually I just pack it myself with an nullsoft installer an use batch-to-exe to run.
Second, do you have anything constructive to add to the conversation, or are you just going to insult OP for not knowing how to do something? Guess what, people don’t know exactly the same things as you just because you’ve learned them before.
OP, what do you mean by manually? Packing the Jar? Yes, but JarSplice isn’t the issue here. The issue is how you are loading your resources. Java is (for lack of a better term) picky about how you load resources in, in different situations. Blaming JarSplice for Java’s confusing IO library is not going to get you a solution.
gives an error. I’ll try to rephrase the question, How do I load textures from the Slick_util.jar into a fat jar. I watched videos on how and I can easily get the libraries and jars, it’s just I don’t have the textures when I run it. I put the res/ folder in the src/ folder now. The textures don’t load still ofcourse.
Exception in thread "main" java.lang.NullPointerException
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
at FSMain.MainFS.main(MainFS.java:67)
Instead of slick_util, should I just use the normal image rendering somehow ??? I have no idea what other way to draw and load them .
For the last time, [icode]new File(…)[/icode] Will. Not. Work. Why? Because those “files” you want to load are zip entries when you export to jar (jar files are actually zip files), not files.
If I’m unclear still, this is exactly what I’m doing.At the very end my results are a blank window for about a second. Please tell me what Im doing wrong, I really need to understand:
Video of what I did: http://www.mediafire.com/watch/oohf1qnh2oefkxp/exportsfail.mp4
public class Foo{
public static SomeOtherClass someOtherClass = new SomeOtherClass();
public Foo(){
// Will not compile, you can not use this to reference a static object
aMethod(this.someOtherClass);
// Instead you would do this
aMethod(Foo.someOtherClass);
}
public void aMethod(SomeOtherClass someOtherClass){
// do something
}
}
Mr.CodeIt, your problems with the command line earlier were a huge shock to me. If you don’t know your way around a command line, then you should not be using an IDE like Eclipse. I cannot stress this enough and how important to learn to compile and run from the command line. You will not get anywhere in life without it.
Now for loading resources, I will explain like I’ve explained too many times in this forum:
java.io.File can only be used to load files on the file system. If the file path you provide to File is a relative path, meaning it does not start with a forward slash or drive letter, it will look relative to the Current Directory. The Current Directory is the directory the program is run from. In Eclipse, this is the root of the project. Since your “res” folder is in the root of the project, then the files are found and all is fine.
However when exporting, since your resources are inside a JAR file (and a JAR file is essentially a ZIP file), you cannot use File. Instead you must use Class.getResource or Class.getResourceAsStream. Both methods find the file the same way, the only exception is that the first returns a java.net.URL object and the second returns a java.io.InputStream, so you use whichever one you need.
Now both methods have 2 ways of looking for the files:
If the provided String does not begin with a leading forward slash, then it looks relative to the location of the Class object you called them on. What is a Class object? Every Java class has an equivalent java.lang.Class instance that goes along with it and there are two ways to get it: MyClass.class and using getClass(). MyClass.class is special syntax that returns MyClass’s Class object. getClass() is a method inside java.lang.Object (which all classes automatically inherit) and it returns the current instance’s Class object. It is best to use the first way as the second returns the Class type that was created, which may be an inherited class! Now for example, say you have a class “my.awesome.package.MyClass”, calling [icode]MyClass.class.getResourceAsStream(“myfile.png”)[/icode] will look inside the “my/awesome/package/” folder for a file named “myfile.png”.
If the provided String does begin with a leading forward slash, then it looks relative to the folder containing the root package, which in Eclipse is the “src” folder. This is why everybody was telling you to move the “res” folder under the “src” folder, as doing [icode]MyClass.class.getResourceAsStream("/res/myfile.png")[/icode] will find it at “src/res/myfile.png”. A nice little trick also is to use getClassLoader() as you have seen. Using a leading forward slash with Class.getResourceAsStream (and getResource) actually calls ClassLoader.getResourceAsStream without the leading forward slash. Both have the same behavior. Therefore, “src/res/myfile.png” can also be found doing [icode]MyClass.class.getClassLoader().getResourceAsStream(“res/myfile.png”)[/icode].
The best part to this long explanation: the linked StackOverflow post and ThinkPlexx article explained it nicely too.