question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add loadJars() to load a directory of JARs

See original GitHub issue

A 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:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
boticcommented, Jun 1, 2021

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.

0reactions
boticcommented, May 25, 2021

So I see three options:

  1. adding a addJarsToClasspath(dir) to the global object. But this is broken by design, since we should never ever add anything to global again.
  2. add addJarsToClasspath(dir) in the engine module, like Manfred proposed. But then we should also add the standard addToClasspath(path) to the engine module, which would be a non-global alternative to addToClasspath(). The global variant would stay as legacy code, the engine alternatives would be the way to go.
  3. Drop this issue and keep copying this snipped.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found