[转述] jruby 对 maven 的支持
程序员文章站
2022-07-14 22:25:38
...
之前开发了 java_side ,主要是便于 jruby 中使用基于 maven 管理的 java 三方包和基于 spring 管理的运行时服务,不过现在 jruby 1.6 以后 maven 这件事可以不必那么麻烦了,根据这篇blog ,我把自己试验的例子贴出来供参考:
- 下载
$ jruby -S gem install mvn:org.springframework:spring Successfully installed mvn:commons-logging:commons-logging-1.1.1-java Successfully installed mvn:org.springframework:spring-2.5.6-java 2 gems installed Installing RDoc documentation for mvn:commons-logging:commons-logging-1.1.1-java... Installing RDoc documentation for mvn:org.springframework:spring-2.5.6-java...
- 使用
$ jruby -S irb jruby-1.6.2 :001 > require 'java' => true jruby-1.6.2 :002 > require 'rubygems' => true jruby-1.6.2 :003 > require 'mvn:org.springframework:spring' => true jruby-1.6.2 :004 > $CLASSPATH << '/home/john/mypro/java/conf' => ["file:/home/john/.rvm/gems/jruby-1.6.2/gems/mvn:org.springframework:spring-2.5.6-java/lib/maven/org.springframework/spring.jar", "file:/home/john/.rvm/gems/jruby-1.6.2/gems/mvn:commons-logging:commons-logging-1.1.1-java/lib/maven/commons-logging/commons-logging.jar", "file:/home/john/mypro/java/conf/"] jruby-1.6.2 :005 > context = org.springframework.context.support.ClassPathXmlApplicationContext.new 'springbeans_development.xml' 2011-7-24 11:49:00 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4f7f1d92: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4f7f1d92]; startup date [Sun Jul 24 11:49:00 CST 2011]; root of context hierarchy 2011-7-24 11:49:00 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [springbeans_development.xml] 2011-7-24 11:49:00 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory 信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@4f7f1d92]: org.springframework.beans.factory.support.DefaultListableBeanFactory@706c08b2 2011-7-24 11:49:00 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@706c08b2: defining beans [sample]; root of factory hierarchy => #<Java::OrgSpringframeworkContextSupport::ClassPathXmlApplicationContext:0x4f7f1d92> jruby-1.6.2 :006 > context.get_bean 'sample' => #<Java::JavaUtil::ArrayList:0xe039859>
附:springbeans_development.xml
<?xml version="1.0" encoding="GB2312"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="byName"> <bean id="sample" class="java.util.ArrayList"> <constructor-arg> <list> <value>sample01</value> <value>sample02</value> <value>sample03</value> </list> </constructor-arg> </bean> </beans>
- 搜索开源包
$ jruby -S gem list mvn:org.mortbay.jetty:jetty -r *** REMOTE GEMS *** mvn:org.mortbay.jetty:jetty (7.0.0.pre.5 java, 7.0.0.pre.4 java, ......) $ jruby -S gem search mvn:org.mortbay.jetty:jetty -r *** REMOTE GEMS *** mvn:org.mortbay.jetty:jetty (7.0.0.pre.5 java, 7.0.0.pre.4 java,......)
下一篇: Ruby中监控文件系统的变化