Sinatra application package in one JAR file?

I have a seemingly (stupid) simple question:

With JRuby, is it possible to deploy one Sinatra application for files?

I mean: I have a Sinatra application with all the necessary gems exploded into some directory ./vendor/lib, and I would like to deploy the whole application as a single jar file to run on the deployment machine:

$ java jar my_app.jar

where the only thing I have is Java.

Is it possible? And if so, is there an easy way to do this?

TIA

+3
source share
3 answers

Warbler . 1.1, Warbler "" . . .

, warbler Sinatra. config.ru, .

$ jruby -S gem install warbler
$ jruby -S warble executable war
$ java -jar my_app.war
+4

. , , - , :

ruby myapp.rb

script lib java-, script. , :

package livesync;

import org.jruby.Ruby;
import org.jruby.RubyRuntimeAdapter;
import org.jruby.javasupport.JavaEmbedUtils;  
import java.util.ArrayList;

public class LiveSyncRunner {
    public static void main(String[] args) {
        String[] jrubyArgs = new String[3 + args.length]; 
        jrubyArgs[0] = "-e";
        jrubyArgs[1] = "require 'livesync/livesync_wrapper'";
        jrubyArgs[2] = "livesync";
        for (int i = 0; i < args.length; ++i) {
            jrubyArgs[i + 3] = args[i];
        }
        org.jruby.Main.main(jrubyArgs);
    }
}

, script lib/livesync_wrapper.rb

build.xml( ) build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="dist" name="Juggernaut">
  <description>Combine Ruby and Java source with the jruby-complete jar</description>
  <target name="dist" description="Create the deliverable jar">
    <taskdef name="jarjar" 
             classname="com.tonicsystems.jarjar.JarJarTask" 
             classpath="vendor/jarjar-1.0rc7.jar"/>
    <mkdir dir="pkg"/>
    <jarjar destfile="pkg/livesync.jar">
      <manifest>
        <attribute name="Main-Class" value="livesync.LiveSyncRunner"/>
      </manifest>
      <fileset dir="classes"/>
      <zipfileset dir="vendor/gems" prefix="vendor/gems"/>
      <zipfileset src="vendor/jruby-complete-1.1.2.jar" />
    </jarjar>
  </target>
</project>

, , , , :

  • Main-Class - java ( ruby ​​ script)
  • / zipfilesets

jruby-complete-1.1.2.jar jarjar-1.0rc7.jar . - .

ant. script

java -jar pkg/livesync.jar args1 agrs2 ...

, !

+2

jruby- jar; . .

jruby.home META-INF , "" jruby. .

, jruby.home, , .

script bin, .

, .

Then mount all the backups by creating a file like app.jar.

Finally, to run:

  java -jar app.jar -S YOUR_SCRIPT

-or- muck about with the manifest and create a java class that is functionally similar to a script.

0
source

Source: https://habr.com/ru/post/1753121/


All Articles