JAR generated by warbler cannot access included internal JAR library - jar

I have a JRuby project that connects to an Oracle database using JDBC via Oracle's ojdbc6.jar library. The code works well when run using JRuby 1.6.6 on Windows 7 and JRuby 1.6.5.1 on OS X Lion. I'm trying to create a standalone JAR file using warbler. After running warble jar it includes the ojdbc6.jar but for some reason it does not load/access it. It seems the internal classpath is incorrect or I'm not configuring something right.
Following directory structure exists.
C:\my_jruby_project\bin\my_jruby_file.rb
C:\my_jruby_project\lib\java\ojdbc6.jar
C:\my_jruby_project\Gemfile
C:\my_jruby_project\Gemfile:
source :rubygems
gem 'activerecord', '>= 3.2.3'
gem 'activerecord-jdbc-adapter', '>= 1.2.2'
gem 'ruport', '>= 1.6.3'
C:\my_jruby_project\bin\my_jruby_file.rb
require 'ruport'
require 'java'
java_import 'oracle.jdbc.OracleDriver'
java_import 'java.sql.DriverManager'
....
After generating the JAR file:
jruby -S warble jar
I execute the jar and get the following error:
C:\my_jruby_project>java -jar my_jruby_project.jar
NameError: cannot load Java class oracle.jdbc.OracleDriver
for_name at org/jruby/javasupport/JavaClass.java:1205
get_proxy_class at org/jruby/javasupport/JavaUtilities.java:34
java_import at file:/C:/Users/DAVIDH~1.OPE/AppData/Local/Temp/jruby8647327738550400677extract/
jruby-core-1.6.7.jar!/builtin/javasupport/core_ext/object.rb:46
(root) at file:/C:/my_jruby_project/my_jruby_project.jar!/my_jruby_project/bin/my_jruby_file.rb:4
load at org/jruby/RubyKernel.java:1058
(root) at file:/C:/my_jruby_project/my_jruby_project.jar!/my_jruby_project/bin/my_jruby_file.rb:1
require at org/jruby/RubyKernel.java:1033
require at file:/C:/my_jruby_project/my_jruby_project.jar!/META-INF/main.rb:36
(root) at <script>:3
C:\my_jruby_project>
The generated JAR includes the lib/java/ojdbc6.jar but it seems internal file or path pointers are not configure correctly.
Appreciate any assistance. Thanks!

You may want to setup $CLASSPATH inside your ruby code.
Something similar to this:
require 'java'
$CLASSPATH << "lib/java/ojdbc6.jar"
I use some extra jars in my jruby on rails project and have the following code in my environment.rb in order for the .jars to be accessible in my .war deployment:
require 'java'
Dir.glob("lib/*.jar").each do |jar|
$CLASSPATH << "#{Rails.root.to_s}/#{jar}"
end

Related

Java can't find native libraries when running Clojure JAR

The project I'm working on is a server-side Clojure project with Leiningen as my build tool.
The problem occurs when I try to run the JAR I created using Leiningen's uberjar.
The JAR is dependent on some native libraries I've placed in: /usr/lib/nativedeps/so.
Before I run the JAR I export the environment variable LD_LIBRARY_PATH with the native libs path so the linker will know where to look for the native libs:
export LD_LIBRARY_PATH=/usr/lib/ctch/so
And then I run it the JAR:
java -jar externalapibe-0.1.0-standalone.jar 3001
Which throws the exception:
java.lang.UnsatisfiedLinkError: no JavaASAPSDK in java.library.path
Which means the linker is unable to find JavaASAPSDK (which is one of the native libs in /usr/lib/nativedeps/so) and that I need to specify the lib path in java.library.path. So I run:
java -Djava.library.path=/usr/lib/nativedeps/so -jar externalapibe-0.1.0-standalone.jar 3001
Which throws the exception:
java.lang.UnsatisfiedLinkError:
/usr/lib/nativedeps/so/libJavaASAPSDK.so: libprotobuf.so.6: cannot
open shared object file: No such file or directory
Which means the lib JavaASAPSDK was found, but another lib called libprotobuf.so.6 (which JavaASAPSDK is dependent on) could not be found.
Problem is both libs are in the same directory!
Any ideas on what can cause this problem and how to solve it???
I solved the problem by deleting:
libprotobuf.so.6
And creating a symbolic link named 'libprotobuf.so.6' to a library that apparantly was identical to libprotobuf.so.6, named libprotobuf.so.6.0.0.
Then I created a configuration file in: /etc/ld.so.conf.d/
touch /etc/ld.so.conf.d/externalapibe.conf
And wrote the path of my native libs in it:
/usr/lib/nativedeps/so
Then I ran:
ldconfig -v | grep /usr/lib/nativedeps/so
Which read the path of my native deps from 'externalapibe.conf' and re-binded the native libs in it.
That seemed to do the work.

How to use extensions

Could someone please explain how one uses the premake extensions. I added the eclipse extension in a directory under my premake installation. And in the premake script I added recuire "eclipse".
Running the script with premake5 eclipse, I get an error module "eclipse.lua" not found.
I added the path of the modules directory to my environment variables.
I'm using premake (premake5) on Windows 8.
Thanks
addons need to reside in a folder. You need to create a "eclipse" folder, then copy all the files in it, and the "eclipse" folder should be located where premake can load it (either next the executable or some other place handled through environment variables)
I got this working by adding the full path to the require statement.
require "C:/premake/eclipse/eclipse"
and running the command as premake5 eclipse
Note: This plugin does not generate project files that one can import into Eclipse.

How can I fix this compile error, when attempting to compile sass using Prepros and Gumby?

I am using windows 7 to compile .scss with an application known as Prepros. (http://alphapixels.com/prepros/ ). I also downloaded the Gumby Framework(http://gumbyframework.com/) into my document root directory of localhost web-server. My goal is to use the gumby framework along with Prepros.
When I attempt to compile the scss file, I am receiving the following error:
Syntax error: Undefined operation: "power(golden_ratio(), 1) times 16px".
on line 52 of Z:/Ampps/www/Gumby-master/sass/extensions/modular-scale/stylesheets/_modular-scale.scss
from line 23 of Z:\Ampps\www\Gumby-master\sass\gumby.scss Use --trace for backtrace.
Also, if it is helpful, this is the config.rb file contained within the folder www\Gumby-master :
# Require any additional compass plugins here.
# Tell compass where to find local extensions
# If you followed directions and ran 'gem install modular-scale' comment the next two lines out:
extensions_dir = "sass/extensions"
Compass::Frameworks.register('modular-scale', :path => File.expand_path("# {extensions_dir}/modular-scale"))
# Uncomment these to use regular Ruby gems.
# require 'modular-scale'
# require 'sassy-math'
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "img"
# You can select your preferred output style here (can be overridden via the command line) :nested or :expanded or :compact or :compressed:
output_style = :compact
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
Lastly,I reviewed this thread, but I did not find it helpful.
SOLUTION: I tried several things to fix this, and I am not absolutely which of them were responsible for fixing it.
Install ruby development kit
Install rails
Install gumby-framework gem (https://github.com/jorgecoca/gumby-framework)
Verify that the modular-scale gem is installed ( https://github.com/Team-Sass/modular-scale)
Use Advanced Prepros options to use third-party compass plugins (http://alphapixels.com/prepros/docs/sass-compass.html) (NOTE: initially I made the mistake of giving this path C:\Ruby193\lib\ruby\gems\1.9.1\gems, when in fact I realized I must provide this one C:\Ruby193\bin\ruby.exe, just like in the picture in the Prepros manual.)
-as stated in this thread, I opened my compass config.rb and commented out Compass::Frameworks.register('modular-scale', :path => File.expand_path("#{extensions_dir}/modular-scale")), and un-commented #require 'modular-scale' and #require 'sassy-math'.
I also ran into this exact same issue. So I would like to share things which I did.
Gumby framework README.md file states "Note: Please use modular scale 1.0.6, 2.x has not been integrated yet". Make sure the version of modular scale installed on your machine is 1.0.6!
How to check?
Let's assume the location of your Ruby installation is "C:\Ruby200".
Go to C:\Ruby200\lib\ruby\gems\2.0.0\gems. In this directory, you will see all the gems that were installed on the machine. (You should see sass, compass, modular-scale among others)
Make sure it says "modular-scale-1.0.6". If it doesn't, then delete the version you have over there. If you see multiple sassy-math over here, don't worry. We just want one modular-scale on the machine!
How to install Modular Scale v1.0.6?
Run gem install modular-scale v 1.0.6
What else to watch out for?
Like Daniel said, open your config.rb. Make sure you have the following lines in it!
#Require any additional compass plugins here.
require 'modular-scale'
require 'sassy-math'
Whatever you do, don't have the following code in your config.rb file. For this code to truly work, you have to have a directory called extensions in your sass directory, and you have to copy all the modular-scale binaries into that directory.
extensions_dir = "sass/extensions"
Compass::Frameworks.register('modular-scale', :path => File.expand_path("#{extensions_dir}/modular-scale"))
If you run into any other problems and somehow manage to solve it, please do add your answer here! The entire installation experience is terrible at the moment.
+1 for Parth Shah -- that worked for me. But the command to install modular-scale 1.0.6 is actually:
gem install modular-scale -v 1.0.6
He missed the hyphen before the v.
BTW as per this date, there has been a Gumby update so that Gumby supposedly now works with these compass, sass and modular-scale versions -- see below for install commands.
gem install compass -v0.12.4,
gem install sass -v3.2.18
gem install modular-scale -v2.0.4
I am still running the older versions but this update has been confirmed by other Gumby users.

Configuring Compass on Windows

I'm on Windows, and I have SASS running successfully in my project. Now, I want to include compass so I can take advantage of the pre-written mixins, etc.
First I simply tried this statement from within my working sass file: #import "compass/css3/transform";
Naturally, this didn't work since I didn't have compass installed, so I navigated to my Ruby directory and successfully installed the compass gem within c:/ruby193/bin. I can now successfully create compass projects within c:/ruby193/bin, but that doesn't do me much good.
I need run compass commands within my site, which lives here: c:/inetpub/mysite. When I try to do so, however, I get compass is not recognized as internal or external command
How can I get compass to work where I want it?
EDIT: a large part of my problem was that Ruby was installed without adding itself to the Windows Path environment variables, so I could only run SASS and Compass commands from within the C:/Ruby193/bin directory. This caused problems for me since, as a result, I thought that was where I needed to install compass. Anyhow, after figuring that out, I still haven't been able to get compass to work, but am planning on uninstaling SASS, Compass, and Ruby and giving this thing another try from scratch. I marked Stooboo's answer as correct since it was the best and most accurate, especially given the information he had to work with. Thanks!
here's how I do it
(One time)
install ruby http://rubyinstaller.org/
install compass, in a command window enter
gem install compass
to add compass to an MVC project, navigate to project folder and in a command window enter
compass create
you will get the default config.rb ... but here is my usual one
http_path = "/"
css_dir = "content/css"
sass_dir = "content/sass"
images_dir = "images"
javascripts_dir = "scripts"
to install bootstrap (for more info see https://github.com/thomas-mcdonald/bootstrap-sass)
add
require 'bootstrap-sass'
to your config.rb
enter (in your command window)
gem install bootstrap-sass
(I had to do a (in your command window)
gem update
after this but you may not need to)
enter (in your command window)
compass install bootstrap
(then ... every time you open the solution in Visual Studio)
navigate to project folder
in a command window enter
compass watch
(this will monitor project for saves and re-compile the scss files)
Hope that helps
Cheers
Stu
To install Compass, you should open your Windows console with Win+R, cmd and run:
gem update --system
gem update
gem install compass
Don't forget to remove all the stuff that you littered you Ruby installation with.
Use this command in order to add GEM to the Windows Path environment variables:
set PATH=C:\Ruby200-x64\bin;%PATH%
In the Ruby command you should write:
gem update --system
(this block of code updates all the gems in the Ruby)
Then you install sass like it:
gem install sass
(You said that you already has sass, so you don't need to write this code again.)
Then, you write this line:
gem install compass
(Now, you will have compass in your machine)
To know the version that was installed, you can write:
compass --version
To create a new project in your desktop machine, you can write this line of code:
compass create desktop/my-project
(This will create a compass folder in the desktop of your machine called my-project. I hope this is helpful.

error trying to run jar file

i have tried to get help me nobody seems to understand my problem. I created a project in netbeans and it produces a jar file when i compiled it. It runs just fine on through the IDE but when i try to launch it from the command prompt it simply does not do anything. It just moves the cursor to the next line for another command? when i echo my classpath this is the result i get
/opt/netbeans-7.1.2/ide/modules/ext/mysql-connector-java-5.1.13-bin.jar:/h/USERS/local/pagola/NetBeansProjects/mylib/dist/mylib.jar:/h/USERS/local/pagola/NetBeansProjects/EOPPrototype/build/classes
i have added the classpath which contains everything that is within the jar. My manifest file contains the main class(entry point) and this is what it looks like
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.13-bin.jar lib/mylib.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: eopprototype.EOPPrototype
and so i cant figure out what i am doing wrong? do i need to add anything to my PATH variable (maybe the java jdk bin stuff) is it not able to locate the java command because it doe not know where to look for that executable?
NOTE: i did not setenv my PATH and LIBRARY PATH -do i need to do this ? this is a c style shell script
Try this first
If your Manifest does not end with a newline it maybe ignored. See manifest requires a newline
Otherwise I have to make assumptions
You don't need lib/mylib.jar in your manifest if that JAR file contains EOPPrototype with a public static void main(String[] args) method that you wish to execute. So remove it so it only lists mysql-connector-java-5.1.13-bin.jar. Your manifest will then look like this
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.13-bin.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: eopprototype.EOPPrototype
Then assuming all your code is in mylib.jar and the only other dependant jar is mysql-connector-java-5.1.13-bin.jar, create a directory structure like this
/h/USERS/temp/mylib.jar
/h/USERS/temp/lib/mysql-connector-java-5.1.13-bin.jar
Then execute like this
cd /h/USERS/temp
java -cp .:mylib.jar eopprototype.EOPPrototype

Resources