[HELP] Library help

Ok, In my game at the moment, if you don’t have the libraries under /lib it will give a main class not found error. How do I fix this, so like if they don’t have the libraries it will try to download it for them? Or at least exit if it doesn’t find the libraries? Right now the JVM isn’t even launched if the libraries are not found so I have no clue.

do you not have the JDK? or is it a library like LWJGL. It doesnt matter really I guess. You jsut have to point the IDE to the file. Lilke with BlueJ it makes you find the JDK before you can start coding. And jsut make a new library for the others.

Thats not the point. The point is to try and… hmm… see if the libraries exist. So far I can’t get it to work because it gives a main class not found error when I don’t have the libraries.

I suppose you could go for a try / catch ClassNotFoundException in the main method solution. Then exit the program in the catch block with a nice message.

However, if you are distributing your game in for example a JAR file, or online in a webstart, you (the programmer / distributor) should be responsible of supplying all required libraries, since the user can’t download the libraries himself and “rebuild” the jar file.

Do you plan to use Java Webstart? In my game, when a user launches it, if he has no JOGL library, it downloads it automatically.

the program doesn’t even launch, so using try/catch is out of the question. ::slight_smile:

Unless i am misunderstanding you, you want certain code paths to be active at runtime if a jar is in lib right? This can be achieved by having a interface to the implementation in your main program and the implementation in another jar, (if your lib doesn’t require arguments to instantiate the class) using the ServiceLoader class and a special file in the implementation jar root. But ServiceLoader only became public with jdk 1.6 so i’d counsel using netbeans lookup that is an external lib. Also the new netbeans will have a cool annotation that will obviate the need to create the Meta inf file by hand… but last time i tried it didn’t work yet.

http://wiki.netbeans.org/DeclarativeRegistrationUsingAnnotations

If its possible, you might also want to register a null object as the default so your code doesn’t have to care if the plugin is installed or not (Though null object has its problems too, imagine a user interface using it).

Edit: I AM misunderstanding you.

@Renoira
Please specify, what “lib” folder you mean. If you consider the JDK lib directory to be a global place where java libraries are installed, you got something wrong. NEVER put any libraries in the JDK or other system directories unless you OBSOLUTELY know what you are doing.

Usually you distribute all the needed libraries with your game and specify the location where to look for them either via the java commandline argument -cp or by listing them in the manifest of your executable jar. Another option is to use webstart and list the dependencies in the jnlp file.

Please describe in more detail what you want to achieve and what the current problem is.

He is probably talking about the local aplication lib folder that netbeans creates when it builds something that needs libraries.

Frankly, it’s a cry of sanity in a eclipse devastated slum.