Created
August 25, 2015 19:14
-
-
Save raelik/0ab65004122f1963f1a5 to your computer and use it in GitHub Desktop.
Using jruby-gradle to create a jruby+dependencies jar, and still have your application code live directly on the filesystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assuming that you're using jruby-gradle 1.0.3, you'll need to take these steps: | |
1. In your build.gradle, in addition to your gems dependencies, you'll need: | |
jrubyJar { | |
initScript runnable() | |
} | |
configurations { | |
jrubyJar { | |
extendsFrom gems | |
} | |
} | |
This will ensure that you end up with a runnable jar that uses org.jruby.mains.JarMain as the | |
Main-Class in META-INF/MANIFEST.MF, and that all your gem dependencies end up in the jar file. | |
Any jar dependencies need to be in the jrubyJar configuration, either directly or by creating | |
another configuration that jrubyJar will extend from in addition to the gems configuration. | |
After running ./gradlew jrubyJar to build your jar, you will end up with a jar file in the | |
build/lib directory in your project root. That will be an executable jar that you can use with | |
the -jar java command line option to run jruby directly. However, by default jruby will use | |
uri:classloader:// as the current directory, in order to find all of the gem and jar dependencies | |
that you have included in the jar file. You'll need to override this with the -C option, giving it | |
the absolute path to your project root. In addition, because you are changing this path, you will | |
need to set the JARS_LOCK environment variable to uri:classloader://Jars.lock, so that the | |
jar-dependencies gem knows to look in the jar file for that, instead of your project root. | |
An example java command to run a script in bin/ or your project root might looks like this: | |
JARS_LOCK=uri:classloader:// java -d64 -server -jar build/libs/your_project-jruby.jar \ | |
-C /var/www/your_project bin/server.rb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment