Weird ClassNotFoundException in Java - Printable Version +- Colobot Forum - International Colobot Community (https://colobot.info/forum) +-- Forum: [Archive] New forum (2015-2019) (https://colobot.info/forum/forumdisplay.php?fid=76) +--- Forum: Others (https://colobot.info/forum/forumdisplay.php?fid=67) +---- Forum: Offtop (https://colobot.info/forum/forumdisplay.php?fid=68) +---- Thread: Weird ClassNotFoundException in Java (/showthread.php?tid=564) |
Weird ClassNotFoundException in Java - CHmSID - 01-11-2015 Hi, this question is mainly aimed at @tomaszkax86 as I know he has some experience with linking lwjgl libraries, but if anybody knows the solution to my problem please do answer I am currently using ant to compile my source code which uses lwjgl for opengl and slick-utils for texture loading. I believe I have my build script set up properly as I am able to compile with lwjgl alone. The weird thing is that even though I appended slick-util.jar to my classpath(which already contains lwjgl jars), the code compiles ok, but throws a ClassNotFoundException followed by a NoClassDefFoundError for a single class file (ResourceLoader) during runtime . The exception is only thrown at runtime and only for that single class(all other classes from slick-util.jar work or at least do not throw any exceptions yet). What I already checked: - classpath in the build script contains slick-util.jar - the script correctly copies the jar file to lib directory used by my application - the jar file contains ResourceLoader.class in a correct path - my imports in the source code are correct I have no idea what else could go wrong. Any ideas anybody? RE: Weird ClassNotFoundException in Java - tomaszkax86 - 01-12-2015 Complete or partial stack trace could help a lot. You don't need to include source code if you don't want to, although I need to know what specific class and method cause this exception. RE: Weird ClassNotFoundException in Java - CHmSID - 01-12-2015 Code: run: The snippet of code which uses the class ResourceLoader: Code: import org.newdawn.slick.util.ResourceLoader; //used here Let me know if you need any more info. RE: Weird ClassNotFoundException in Java - krzys_h - 01-12-2015 (01-11-2015, 07:18 PM)CHmSID Wrote: - the script correctly copies the jar file to lib directory used by my applicationAre you 100% sure it actually loads the file from this location? RE: Weird ClassNotFoundException in Java - CHmSID - 01-12-2015 Quote:Are you 100% sure it actually loads the file from this location? my dev directory contains three directories: source, lib and data. When I build the project, a new directory is created called dist where both data and lib directories are copied to with their content, then a jar file is also generated there. By doing this, I know that the dist folder will contain the exact same files that are in my development directory. I also know that by running the "run" task, I'm not in the same directory as the jar file I'm trying to run. But because the folder structure is the same and the contents are exactly the same, I don't think it matters. I'm pretty sure the jar file containing the library is loaded at the very least during the compilation, because there are no errors. I also tried to set up the classpath for runtime manually and run the jar from it's directory but it also didn't work. The fact that only one class out of entire library could not be found throws me off... RE: Weird ClassNotFoundException in Java - tomaszkax86 - 01-13-2015 This is a very strange error. Have you tried creating empty project and running just this class's method? I downloaded newest library and executed ResourceLoader.getResource() method alone with some argument and it worked fine. RE: Weird ClassNotFoundException in Java - CHmSID - 01-13-2015 Solved. Sorry for all the trouble, it's the little detail that's always the culprit I had the class path set up correctly for the jar creation, but I forgot to include the library jar path in the manifest.mf I was copying into the jar Embarrassing, sorry I came to the solution by comparing my jar with the jar created by JarSplice(which worked), and I noticed the said lib is missing... edit: how do I give you reputation for helping me? RE: Weird ClassNotFoundException in Java - Simbax - 01-13-2015 Go to one's profile and click "Rate". Also, remember that giving like is like giving 1 reputation point. You can give maximally 5 reputation points a day as I remember. RE: Weird ClassNotFoundException in Java - tomaszkax86 - 01-13-2015 It's OK, we all make embarrassing mistakes sometimes. The one I remember well is that I forgot one time that Class-Path attribute in manifest needs a space separated list of files, not semicolon separated like the one in -classpath switch. Took me a while to figure out what was wrong. Since you are using Ant to compile your project, I can tell you about a nice trick. You can create manifest attributes directly in build.xml. Useful if you have few attributes because you don't have to make manifest file outside. Put something like this into <jar> task: Code: <manifest> More info here: https://ant.apache.org/manual/Tasks/jar.html RE: Weird ClassNotFoundException in Java - CHmSID - 01-14-2015 Thanks, makes my directory a little bit cleaner now |