Hi folks, here is an example of what I want to do: I have a ruby script 'prime.rb' with a method 'isPrimeNumber(num)' which should be compiled into a JAR 'prime.jar'. It should be possible to use this JAR from a Java class main.java which compiles to main.jar and calls the described method to check if a number is a prime number. => basically I need to compile the JRuby script to a Java bytecode compatible JAR The conditions are: - everything must be done via Maven (note: Maven 'knows' Ant as well) - no program can be manually installed - only Maven and the JDK are present on the PC I asked a similar question quite a while ago (http://www.ruby-forum.com/topic/208555#new), but didn't get satisfactory replies - yet I am still interested in this. Cheers, Stephanos
on 2010-08-24 11:48
on 2010-09-03 20:19
BTW, to simplify my question: Is there any way to use the jruby-complete.jar (via Ant) in order to compile a script.rb to script.class ? Stephan Be wrote: > Hi folks, > > here is an example of what I want to do: > I have a ruby script 'prime.rb' with a method 'isPrimeNumber(num)' which > should be compiled into a JAR 'prime.jar'. It should be possible to use > this JAR from a Java class main.java which compiles to main.jar and > calls the described method to check if a number is a prime number. > => basically I need to compile the JRuby script to a Java bytecode > compatible JAR > > The conditions are: > - everything must be done via Maven (note: Maven 'knows' Ant as well) > - no program can be manually installed - only Maven and the JDK are > present on the PC > > I asked a similar question quite a while ago > (http://www.ruby-forum.com/topic/208555#new), but didn't get > satisfactory replies - yet I am still interested in this. > > Cheers, > Stephanos
on 2010-09-06 16:39
Stephan,
From the original thread: http://www.ruby-forum.com/topic/208555#new
1. create a directory called temp:
mkdir temp
2. copy these two files into it:
pom.xml:
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<name>test</name>
<version>0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks name="compile some jruby codekata">
<!--
http://ant.apache.org/manual/CoreTasks/exec.html -->
<exec dir="${basedir}"
executable="jrubyc" failonerror="true">
<arg line="somescript.rb"/>
<arg line="."/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
somescript.rb:
puts 'Hello world'
Except beyond that add a task that adds "${basedir}" to the classpath
(via ant config of the ant task in the maven pom.xml) and calls
jruby.jar somescript (without the .rb). Maybe you could add a task to
grab the jruby jar from some external source if you couldn't use it as a
dependency.
Good luck,
Gary
on 2010-09-06 20:40
Hm, I'm not sure I understand what is actually different to the post you
did originally.
Are you saying I should simply use jrubyc?
Or are you saying I should use the jruby.jar and execute the script
'dynamically'?
Either way, the requirements are not fulfilled ("no program can be
manually installed" [!jrubyc] and/or "Java bytecode" [!dynamic]).
Or am I not getting it?
I was hoping for something like
'http://stackoverflow.com/questions/231550/has-anyone-used-or-written-an-ant-task-to-compile-rhino-javascript-to-java-byte/231750#231750'.
Isn't the code for jrubyc inside the jruby-complete.jar anyway?
Cheers,
stephanos
Gary Weaver wrote:
> Stephan,
>
> From the original thread: http://www.ruby-forum.com/topic/208555#new
>
> 1. create a directory called temp:
>
> mkdir temp
>
> 2. copy these two files into it:
>
> pom.xml:
>
> <?xml version="1.0"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>test</groupId>
> <artifactId>test</artifactId>
> <name>test</name>
> <version>0.1</version>
> <build>
> <plugins>
> <plugin>
> <artifactId>maven-antrun-plugin</artifactId>
> <executions>
> <execution>
> <phase>install</phase>
> <configuration>
> <tasks name="compile some jruby codekata">
> <!--
> http://ant.apache.org/manual/CoreTasks/exec.html -->
> <exec dir="${basedir}"
> executable="jrubyc" failonerror="true">
> <arg line="somescript.rb"/>
> <arg line="."/>
> </exec>
> </tasks>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> </executions>
> </plugin>
> </plugins>
> </build>
> </project>
>
>
> somescript.rb:
>
> puts 'Hello world'
>
> Except beyond that add a task that adds "${basedir}" to the classpath
> (via ant config of the ant task in the maven pom.xml) and calls
> jruby.jar somescript (without the .rb). Maybe you could add a task to
> grab the jruby jar from some external source if you couldn't use it as a
> dependency.
>
> Good luck,
> Gary
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.