vertx-lang-js icon indicating copy to clipboard operation
vertx-lang-js copied to clipboard

java Build/Gradle + FatJar accessing relative folder paths does not work without additional classloader logic

Open StephenOTT opened this issue 8 years ago • 2 comments

Build a fat jar with the following project: https://github.com/StephenOTT/js-vertx-fatjar

Have some deployment code such as:

function deployRubyVerticle() {

  var classloader = java.lang.Thread.currentThread().getContextClassLoader();
  var bundleFolderResource = classloader.getResource('ruby_gems')
  console.log('ruby_gems absolute path: ' + bundleFolderResource.getPath())

  var rubyOptions = {
    "config": {
      "GEM_PATH": bundleFolderResource.getPath() + "/vendor/bundle/jruby/2.3.0/"
    },
    "worker" : true
  }
  vertx.deployVerticle('verticles/ruby-working-hours/working-hours-vert.rb', rubyOptions)
}

If you dont have the classloader based path, and just use the regular GEM_PATH = "./my/relative/path", its not using the root of the project/jar. The typical error would be "File not found" as the path could not be found.

The classloader stuff was required because when GEM_PATH is used in a config its loading from what appears to be current working directory ( ? ) This problem does not occur when using the Docker stack cli, because the CWD is set during the image build.

I used: https://github.com/vert-x3/vertx-lang-js/commit/d4323889e71b21e35a873a73fb939eba53c2d0de#diff-a5533d7f2941dd2c95a4d7a28f1106afR294 and https://github.com/vert-x3/vertx-lang-js/pull/30 and https://github.com/vert-x3/vertx-lang-js/issues/29 as my logic trail to come up with this solution.

This seems like it would be a change for Ruby lang to have better support? Or is just this a "fact" of building JS/Nashorn Laucher.class based builds (fatjars, etc)

Another option could be to add additional config options for GEM_PATH that would indicate to use classloader context, or ENV var VERTICLE_HOME rather than cwd ?

@pmlopes @vietj

StephenOTT avatar Mar 12 '18 19:03 StephenOTT

I think we can have solution iwth classloader for ruby as long as it remains simple and is tested

vietj avatar Mar 13 '18 06:03 vietj

@vietj i gues this is the same solution that @pmlopes mentioned on gitter? https://github.com/pmlopes/vertx-lang-es/blob/master/src/main/resources/jvm-npm.js#L23-L67

StephenOTT avatar Mar 13 '18 19:03 StephenOTT