Add loadJars() to load a directory of JARs
See original GitHub issueA lot of applications have code like the following to load all JARs from a given directory into the class path. Should we provide it out of the box and if yes, in what module?
/**
* Loads all .jar files placed in the `jars` directory of SqlStore
*/
var loadJars = exports.loadJars = function() {
// add all jar files in jars directory to classpath
var dir = module.resolve("../../../jars/");
var repo = getRepository(dir);
var list = repo.getResources().filter(function(r) {
return strings.endsWith(r.name, ".jar");
});
list.forEach(function(file) {
addToClasspath(file);
});
};
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Java load jar files from directory - Stack Overflow
Read all the files in a specific directory · Convert the File reference to a URL for each result · Use a URLClassLoader...
Read more >8 Understanding WebLogic Server Application Classloading
The extensions classloader loads any JAR files placed in the extensions directory of the JDK. This is a convenient means to extending the...
Read more >Calling Out to a Third-Party Jar from Groovy - Confluence
The script assumes that the jar files and dependencies have been copied into the "lib" folder as part of the Aspire distribution. Example...
Read more >5 ways to add multiple JAR in to Classpath in Java - Examples
This is another way you can add multiple JAR in your classpath. JAR from ext directory is loaded by extension Classloader and it...
Read more >terl/resource-loader: Getting files out of a JAR or loading a ...
// Top-level build.gradle · // ... mavenCentral() } dependencies { ; File file = ; // The following loads test1.txt from the resources...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pull request: #425
I decided to go with
loadJars()
, since it takes a repository (or path treated as one) and looks for matching resource names.addToClasspath()
is already blocked by the global function.So I see three options:
addJarsToClasspath(dir)
to the global object. But this is broken by design, since we should never ever add anything to global again.addJarsToClasspath(dir)
in the engine module, like Manfred proposed. But then we should also add the standardaddToClasspath(path)
to the engine module, which would be a non-global alternative toaddToClasspath()
. The global variant would stay as legacy code, the engine alternatives would be the way to go.