I'm developing an application using Eclipse IDE. I've the following method: Code: public LinkedList<String> getClusteringAlgorithms()
throws Exception {
ret.add(StaticUtils.removeExtension(classes[i]
Code: Class Constants: public static final String CLUSTERING_ALGORITHMS_DIR
= "bin/es/uc3m/beruby/signal/clustering/algorithms/";
This method, basically, allows me to get the "avalaible" clustering algorithms looking into the folder where the ".class" of the classes associated to the algorithms will be. When I execute my application from Eclipse everything works fine. However, I want to make the application avalaible out of eclipse (via JAR file) and here is when the problems begins. If I create the JAR from eclipse, I told eclipse to create a separate folder to include the libraries associated to the project and I create the JAR. When I execute the application it can't load the clustering algorithms (I suppose because the path of CLUSTERING_ALGORITHMS_DIR is different when you are executing it from a JAR file). How to solve this problem? Solution: For finding classes within the classpath (which could be the classes folder, or inside a jar file), I have done similar using the "scannotation" project. The idea is to read look at the class files without actually loading them, because that wastes the class loader area of the java vm memory. Where scannotation project aims to find classes tagged with a given annotation, perhaps the ClasspathUrlFinder would be a good example of how to find the starting point of classes in the classpath without having to hard code the file system path. Perhaps the logic could be extended to find classes that implement the clutering interface. Another idea, if you assume the algorithms folder is always in the same folder where your application.jar file is, and when you run the application.jar file, we can determine the file system location for where ever this is with something like : Code: /**
return path;
/**
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|