I try to make a .JAR from a simple ruby sample. In MRI and jRuby i can run this without problem but when i try to warble the project i get error when i run the JAR file.
Errno::ENOENT: No such file or directory - configuration.yml
The configuration.yml file is not in the project folder because is needs to be editable so shouldn't be in the JAR included, optimally the path would be relative to the jar so that the YML file is in the same folder as the JAR file. So how could i do this ?
My bin\sample.rb
require 'yaml'
#conf = YAML::load_file "c:/test/configuration.yml"
##conf = YAML::load_file "c:\\test\\configuration.yml"
puts #conf['username']
My c:\test\configuration.yml
username: test
My .gemspec file
Gem::Specification.new do |spec|
spec.require_paths << '.'
}
My config\warble.rb
Warbler::Config.new do |config|
config.jar_name = "sample"
end
I warble with "warble jar -trace" and get no errors
I use jruby-1.7.4 and warbler-1.3.8.
Figured it out without using java as some solutions on the web suggest (but not for warble).
require 'yaml'
scriptpath = __FILE__[/(.*)\/.+\.jar!/]
yamlpath = "#{$1[6..-1]}/configuration.yml"
#conf = YAML::load_file(yamlpath)
puts #conf['username']
# => test
Related
when i run my apps in Idea it is good. But when i package and run with java -jar in linux. I got this exception.
exception
the problem code is
val config = ConfigFactory.parseFile(new File("src/main/resources/master.conf"))
master = context.actorSelection(s"akka.tcp://masterSystem#${config.getString("akka.remote.netty.tcp.hostname")}:${config.getString("akka.remote.netty.tcp.port")}/user/Master")
the structure of my module
src/main/resources path doesn't exist in your jar and that's by design.
Try first getting your config in your code like this:
val config = ConfigFactor.load()
and then pass java -Dconfig.location=master.conf jar ... to your program
I installed Clojurescript following its quick start guide.
I pulled the git repo to ~/clojurescript.
CLOJURESCRIPT_HOME is set ~/clojurescript and clojurescript/bin is added to system path.
When I try to use commands cljsc I get following error
Could not find or load main class clojure.main
How can I solve it?
Alright coming back after 5 years.
This error surfaces when one runs clj --main cljs.main --compile hello-world.core --repl from directory or path which does not have file deps.edn or cljs.jar.
Considering the directory structure at https://clojurescript.org/guides/quick-start,
hello-world #### Run that command in this directory
├─ src
│ └─ hello_world
│ └─ core.cljs
├─ cljs.jar
└─ deps.edn
i.e.
$ cd hello-world
$ clj --main cljs.main --compile hello-world.core --repl
I was going through this tutorial today.
I checked here for this error. The version of the standalone jar was correct. The problem was caused by a 'typing mistake' in the core.cljs file. The string "Hello world!" was not in double quotes. Initially the string was in single quotes and included a comma.
The other issue I struggled with was getting the java command to work. I was using a Cygwin64 Terminal.
The correct command for the Cygwin64 Terminal is:
$ java -cp "cljs.jar;src" clojure.main build.clj
In my case, I was typing Windows command by mistake which has " in the command + make sure you'll have the cljs.jar in your root folder bes
java -cp cljs.jar:src clojure.main build.clj
I hope it helps someone, one day.:)
If you have created your project using leiningen then your project cli would look something like this
(defproject clojuredemo "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]]
)
After the :dependencies add the following lines
:jar-name "<project-name>.jar"
:jar-path "/target/<project-name>.jar"
Note : you need the replace the project name with your project
After that run the following command
lein jar
Ensure that the JAR file at classpath exists:
java -cp target/missing-file.jar clojure.main your.namespace
will confusingly throw Could not find or load main class clojure.main.
I'm using compass with a non-Rails project. I have a config file at:
config/compass.rb
My config file looks like this:
http_path = "/"
css_dir = "./example"
sass_dir = "./example/sass"
images_dir = "./example/images"
javascripts_dir = "./example/js"
output_style = :compressed
relative_assets = true
And I'm starting Compass using:
compass watch -c config/compass.rb
When I run this, compass just hangs. If I run compass using --trace and quit, I get the following stack-trace:
^CInterrupt on line ["18"] of /Users/me/.gem/ruby/2.0.0/gems/compass-rails-2.0.0/lib/compass-rails.rb:
/Users/me/.gem/ruby/2.0.0/gems/compass-rails-2.0.0/lib/compass-rails.rb:116:in `configuration'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/configuration/helpers.rb:21:in `configuration_for'
/Users/me/.gem/ruby/2.0.0/gems/compass-core-1.0.0.rc.1/lib/compass/configuration.rb:139:in `add_configuration'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/configuration/helpers.rb:79:in `add_project_configuration'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/commands/project_base.rb:37:in `add_project_configuration'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/commands/project_base.rb:25:in `configure!'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/commands/project_base.rb:15:in `initialize'
/Users/me/.gem/ruby/2.0.0/gems/compass-1.0.0.rc.1/lib/compass/commands/update_project.rb:41:in `initialize'
So it appears that rather than using the compass gem, calling compass watch is using compass-rails which expects configuration arguments I'm not supplying and hangs.
$ which compass returns: /Users/me/.gem/ruby/2.0.0/bin/compass
Why is this and how can I work around it?
To get this working I used Bundler and ran:
$ be compass watch -c ./config/compass.rb
Note be is an alias for bundle exec.
I'm still unsure how compass-rails was hooking into compass.
I would like to ask, how can I load new module in Kamailio 4.1.2?
Actually, I have an issue, when I tried to compile my kamaiio.cfg
I've got error:
root#kamailio:/usr/local/# kamailio -c kamailio.cfg
loading modules under /usr/local/lib64/kamailio/modules/
0(25392) ERROR: <core> [sr_module.c:587]: load_module(): ERROR: load_module: could not find module <websocket> in </usr/local/lib64/kamailio/modules/>
0(25392) : <core> [cfg.y:3408]: yyerror_at(): parse error in config file /usr/local/etc/kamailio/kamailio.cfg, line 323, column 12-25: failed to load module
0(25392) ERROR: <core> [cfg.y:3272]: yyparse(): cfg. parser: failed to find command ws_handle_handshake
0(25392) : <core> [cfg.y:3411]: yyerror_at(): parse error in config file /usr/local/etc/kamailio/kamailio.cfg, line 1083, column 27: unknown command, missing loadmodule?
ERROR: bad config file (2 errors)
when I look physically to the /usr/local/lib64/kamailio/modules/ there is some modules, but websocket.so is missing.
So, how can I get and load module in Kamailio?
Thank you for help!
You haven't installed the module websocket. Edit modules.lst file in the source code directory and add websocket to include_modules variable. If you don't have modules.lst, just do:
make cfg
Alternative is to do:
make cfg include_modules="websocket"
By default, the build system for kamailio compiles and install only the modules that have the same dependencies as the core of the application. For websocket you need to install libunistring and openssl (libssl) devel packages.
Steps to load new module to Kamailio server. (Try if above answer is not working for you)
Check the modules is exist in the default module directly /usr/local/lib64/kamailio/modules.
If found, add loadmodule "module_name.so" in load module section in kamailio.cfg file.
If the module is not found in default module directory, you can check for the source code of that module in the default module source code directory /usr/local/src/kamailio-4.4/kamailio/modules.
If source code found, enter to the module directory. Then create modules' shared object file(.so) by following commands.
./configure
make
make test
make install
Then you will get a shared object file(.so). Copy that file into the default module directory. and load this module from the kamailio.cfg file as mentioned in step 1.
If module source code does not exist in the default source code directory, You need to download the source code from the web. And follow step 3 and 4.
I'm trying to write a script that is executed with the jruby-complete.jar like so:
java -cp derby.jar; -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver -jar jruby-complete.jar -S my_script.rb
I'm using JVM 1.6.0_11 and JRuby 1.4.
In my jruby script I attempt to connect to the database like this.
connection = Java::com.sql.DriverManager.getConnection("jdbc:derby:path_to_my_DB")
This throws a java.sql.SQLException: "No suitable driver found" exception.
I've tried manually loading the driver into the class loader using Class.forName which gives me the same error.
It looks like to me that the class loader being used by the DriverManager is not the same as the current thread's. I've tried setting the current thread's class loader using:
JThread = java.lang.Thread
...
class_loader = JavaLang::URLClassLoader.new(
[JavaLang::URL.new("jar:file:/derby.jar!/")].to_java(
JavaLang::URL),JRuby.runtime.jruby_class_loader)
JThread.currentThread().setContextClassLoader(class_loader )
But this doesn't help.
Any ideas?
OK I downloaded jruby-complete.jar and had a go....
This seems to work for me:
java -classpath c:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar;jruby-complete-1.4.0.jar org.jruby.Main -S derby.rb
When using the -jar switch, the -classpath option is ignored (maybe the CLASSPATH shell var is too). But on the above line, we put both required jars on the class path and pass the class name to execute (i.e. org.jruby.Main). The script being passed in is as per my other answer.
Another option (which I have not tried) would be to alter the jruby-complete.jar manifest file to specify as classpath, as described here:
Adding Classes to the JAR File's Classpath
First, make sure your driver jar is not corrupted (this made me waste a couple of days one time).
Second, read this about JRuby/Java classloade: JRuby Wiki
Third (because I haven't played with "jruby-complete") try this simple script and then see if you can adapt as you need.
require 'java'
require 'C:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar' # adjust for your machine
include_class "java.sql.DriverManager"
derby = org.apache.derby.jdbc.EmbeddedDriver.new
connection = DriverManager.getConnection("jdbc:derby:derbyDB;create=true")