Rawr-created jar throws ClassDefNotFoundError - jruby

I am trying to use Rawr to turn a simple 3-file Ruby project into an executable jar to be run on Ubuntu. I ran jruby -S rawr install to create the Rakefile and set up the directory layout. All my .rb files are under the src directory at the root of the project. When I run jruby -S rake rawr:jar, it compiles all the Ruby files and creates the jar just fine. It then places it in my deploy directory along with lib/java/jruby-complete.jar.
I try executing the jar from inside deploy with java -jar hg_analyzer.jar. However, when I do this I am greeted with this error:
Exception in thread "main" <script>:1:in `require': Linkage error loading compiled script; you may need to recompile 'file:/home/marcw/Documents/hg_analyzer/deploy/jar/hg_analyzer.jar!/main.class': java.lang.NoClassDefFoundError: org/jruby/ast/executable/AbstractScript$RuntimeCache (LoadError)
from <script>:1
...internal jruby stack elided...
from Kernel.require(<script>:1)
from (unknown).(unknown)(:1)
I've also tried running it as java -cp lib/java/** -jar hg_analyzer.jar, but to no avail. The Class-Path entry in the jar's manifest file looks okay as well. main.rb is the main Ruby file.
Running java with the -verbose option shows that it is finding the JRuby jar and is loading it from the expected location.
Any ideas?

Figured it out! The problem was that Rawr was downloading version 1.5 of the JRuby runtime and I have version 1.4 of the compiler on my system.

Related

Koala with "sass-json-vars": CLI works, but GUI gets "Cannot load such file sass-json-vars"

I have C:\Program Files (x86)\Koala\ruby\lib\ruby\bin added to the PATH environment variable.
When I install this gem with gem install sass-json-vars, it's installed to C:\Program Files (x86)\Koala\ruby\lib\ruby\gems\2.0.0\gems
When I run the command sass core.scss core.css -r sass-json-vars --trace, it works fine.
But if I open koala-config.json in my project-root and add "customOptions": ["-r sass-json-vars"],, each attempt by the GUI, or the GUI's 'watcher', to compile gives me the error "Cannot load such file -- sass-json-vars".
If I remove the command, and the attempt to import json, the GUI works fine.
The solution was running the following command:
gem install -i "C:\Program Files (x86)\Koala\rubygems" sass-json-vars, or similar syntax for any other gem if anyone should encounter this problem.

Can't install json (Ruby doesn't work)

windows 10. ruby 2.2.4. I've tried all the devkit stuff and whatever to fix this. I've looked stuff up for hours and hours with no success. When I try to bundle it doesn't install json. When I try to install json it says
"Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20160303-4132-alefq2.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
'make' is not recognized as an internal or external command,
operable program or batch file.
make "DESTDIR="
'make' is not recognized as an internal or external command,
operable program or batch file.
make failed, exit code 1
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-1.8.3 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/json-1.8.3/gem_make.out"
I was facing the same problem. The Gemfile.lock in the repo I cloned had a json version older than the one I had already installed. I did not manage to uninstall the newer version, but I did replace the old version number in the Gemfile.lock with the new one and it seems to work now.
You should run the devkit installation scripts.
In particular, pay attention to devkitvars.bat.

Failed sqljdbc4 connection when in executable JAR

I have a GUI application that connects to a SQL Server 2008 database using sqljdbc4.jar. If I run this from the command line it works great.
However, once I wrap it into an executable JAR, I get a "No suitable driver found for jdbc:sqlserver://myServer:1433;databaseName=myDb" error. I know that my Windows system CLASSPATH is ignored once it's in a JAR, but I can't figure out include the sqljdbc4.jar within the executable JAR and get a portable application.
My most recent attempt to fix this is as follows:
My MANIFEST.MF file:
Manifest-Version: 1.0
Class-Path: lib/sqljdbc4.jar
Created-By: 1.7.0_11 (Oracle Corporation)
Main-Class: MyApp
The command I use to compile the JAR:
jar cmf MANIFEST.MF MyApp.jar MyApp.class help.html lib
My directory structure is below. I am running the jar command inside the MyApp directory.
+ MyApp
+ lib
- sqljdbc.jar
- help.html
- MANIFEST.MF
- MyApp.class
- MyApp.java
When I create the JAR and run it inside the MyApp directory, it works fine. As soon as I pull it out of the directory, I get the error. How can I make the JAR access the sqljdbc.jar that is available internally?
Thanks in advance.
When you have an executable jar MyApp.jar with entry in the manifest.mf:
Class-Path: lib/sqljdbc4.jar
This means that the jar has an external dependency to sqljdbc4.jar in the (relative) folder lib. It is not included in the jar you created! So you need to make sure that there is a lib-folder containing sqljdbc4.jar relative to that jar when you execute it. So the folder structure when executing needs to be;
+ (a folder)
+ lib
- sqljdbc.jar
- MyApp.jar

Ruby (Rack) application could not be started - mysql library error

Bluehost just upgraded their MySql version and broke my application.
I now get "Ruby (Rack) application could not be started" and this specific file load error:
libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - /home4/mychairs/ruby/gems/gems/mysql2-0.3.11/lib/mysql2/mysql2.so
Notice the super long root-based path.
Running
bundle install
via SSH and then
bundle show mysql2
I am told that I am using this library:
/home4/mychairs/ruby/gems/gems/mysql2-0.3.11
I cannot tell where the abnormal path is being generated.
Remove the mysql gem manually and reinstall it via 'bundle install'. Bundler has no idea the underlying MySQL lib has changed, it just knows that the gem is there.

Executing rake tasks on an exploded war on tomcat without jruby being installed

My rails project is deployed to tomcat with the help of warbler, but I need to be able to run rake tasks on that server.
Stay tuned. I hope to have this capability in Warbler 1.4. Jake Goulding, a community member, has been doing some great work on this.
Until then, a typical approach would be to ensure all your Rake and database scripts are present in the war file, then just unpack it somewhere, cd to WEB-INF inside the unpacked war, and run something like java -cp lib/jruby-core*.jar:lib/jruby-stdlib*.jar org.jruby.Main -S rake -T.