{"id":18909183,"url":"https://github.com/jruby/jruby-mains","last_synced_at":"2025-04-15T06:15:25.087Z","repository":{"id":25694906,"uuid":"29131157","full_name":"jruby/jruby-mains","owner":"jruby","description":"a couple of main methods for embedded (j)ruby inside a jar/war file","archived":false,"fork":false,"pushed_at":"2017-11-15T16:07:27.000Z","size":137,"stargazers_count":10,"open_issues_count":5,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T06:15:18.973Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-12T10:48:52.000Z","updated_at":"2022-11-13T20:16:44.000Z","dependencies_parsed_at":"2022-07-25T14:52:10.340Z","dependency_job_id":null,"html_url":"https://github.com/jruby/jruby-mains","commit_stats":null,"previous_names":["mkristian/jruby-mains"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-mains","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-mains/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-mains/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-mains/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jruby","download_url":"https://codeload.github.com/jruby/jruby-mains/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016641,"owners_count":21198833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T09:31:35.395Z","updated_at":"2025-04-15T06:15:25.069Z","avatar_url":"https://github.com/jruby.png","language":"Ruby","readme":"# jruby-mains\n\n## vision\n\n* install your gem and jar dependencies into some directory /tmp/myapp\n* pack the gems + jars into gems.jar\n* pack the whole application as it into application.jar\n* run the application from these jars or put them along jruby.jar and jruby-rack.jar into WEB-INF/lib\n\n### current situation\n\nNOTE: at the time of writing you need to use jruby-complete.jar from [https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-complete/1.7.20-SNAPSHOT/](https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-complete/1.7.20-SNAPSHOT/) for the examples. jruby-mains itself work with old jruby versions.\n\nfirst pack all the gem and jar dependencies into one jar:\n\n\texport JARS_HOME=/tmp/app/jars\n\texport GEM_HOME=/tmp/app\n\texport GEM_PATH=/tmp/app\n\tgem install bundler\n\tbundle install\n\n\trmdir /tmp/app/doc /tmp/app/extensions /tmp/app/build_info\n\trm -rf /tmp/app/cache\n\tjar -cvf gems.jar -C /tmp/app .\n\nnow pack the application:\n\n\tjar -cvf application.jar .\n\nnow run these jars with\n\n\tjava -cp application.jar:gems.jar:jruby-complete.jar org.jruby.Main -C uri:classloader:/ -S rackup\n\nthis is equivalent to (here the classloader finds the application on the classpath \".\")\n\n\tjava -cp .:gems.jar:jruby-complete.jar org.jruby.Main -C uri:classloader:/ -S rackup\n\nor very close to (the current directory is on the file system and not inside the classloader)\n\n\tjava -cp .:gems.jar:jruby-complete.jar org.jruby.Main -C . -S rackup\n\nthe last can be reduced to (since ```GEM_PATH``` and ```JARS_HOME``` needs to be set)\n\n    java -jar jruby-complete.jar $GEM_PATH/bin/rackup\n\nthe only difference is from where the application is loaded and where the current directory (-C) is pointing to. \n\nnote: if ```GEM_PATH``` and ```JARS_HOME``` are not set then JRuby is looking for gems and jars in ```uri:classloader:/```.\n\nideally bundler should be only development dependency and then can be excluded.\n\n## what about war files ?\n\njust put the jruby-complete.jar, jruby-rack.jar, application.jar and the gems.jar into **WEB-INF/lib** and configure your **WEB-INF/web.xml** to use the classpath-layout\n\n    \u003cweb-app\u003e\n      \u003ccontext-param\u003e\n        \u003cparam-name\u003ejruby.rack.layout_class\u003c/param-name\u003e\n        \u003cparam-value\u003eJRuby::Rack::ClassPathLayout\u003c/param-value\u003e\n      \u003c/context-param\u003e\n\n      \u003cfilter\u003e\n        \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n        \u003cfilter-class\u003eorg.jruby.rack.RackFilter\u003c/filter-class\u003e\n      \u003c/filter\u003e\n      \u003cfilter-mapping\u003e\n        \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n        \u003curl-pattern\u003e/*\u003c/url-pattern\u003e\n      \u003c/filter-mapping\u003e\n\n      \u003clistener\u003e\n        \u003clistener-class\u003eorg.jruby.rack.RackServletContextListener\u003c/listener-class\u003e\n      \u003c/listener\u003e\n    \u003c/web-app\u003e\n\nthen the web-application uses the same loading semantic as the standalone execution.\n\nof course you can just unpack the gems.jar and application.jar into **WEB-INF/classes** which does not make a difference since from both location all the ruby sources are loaded via the jruby-classloader.\n\n## using jruby-mains\n\nthis jruby-mains artifact expect the gems and jar dependencies be vendored at the root of the application.jar\n\n\tJARS_HOME=./jars GEMS_HOME=. GEMS_PATH=. bundle install\n\tjar -cvf application.jar .\n\nand run it with\n\n    java -cp application.jar:jruby-complete.jar:jruby-mains.jar org.jruby.Main bin/rackup\n\nor via the **-S** switch\n\n\tjava -cp application.jar:jruby-complete.jar:jruby-mains.jar org.jruby.mains.JarMain -S rackup\n\nfinally you can merge those three jar files into one and set the entry-point to **org.jruby.mains.JarMain**. this reduces the execution to\n\n\tjava -jar application-uber.jar -S rackup\n\nsome executables spawn a new ruby process which is not working from a jruby-complete exectution. but in such cases you can use the entry-point **org.jruby.mains.ExtractingMain** which unpacks the jar into a temporary directory and then executes the application.\n\n# development\n\nuse maven 3.3.x or the supplied ```mvnw``` wrappers. all integration tests in **src/it** are using the ruby pom DSL the pom.xml is just a dummy for the invoker plugin to find the test.\n\n# license\n\nAlmost all code is under the LGPL-3 license.\n\n# contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n# meta-fu\n\nreport issues and enjoy :) \n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-mains","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjruby%2Fjruby-mains","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-mains/lists"}