Reputation: 15882
Is there a way to package a jruby script as a .jar file with support for annotations? I don't think warbler does this. jruby2java looks like it supported annotations but it hasn't been updated in four years.
Upvotes: 2
Views: 201
Reputation: 26763
The JRuby compiler, which is part of the core JRuby features, has the java_annotation
method that allows you to define annotations in your JRuby code.
Here is an example with Spring MVC annotations, where annotations are added on the class GreetingController
, and on the print
method:
java_import 'org.springframework.stereotype.Controller'
java_import 'org.springframework.web.bind.annotation.RequestMapping'
java_import 'org.springframework.web.bind.annotation.RequestMethod'
java_import 'org.springframework.ui.ModelMap'
java_package 'com.weblogism.myapp'
java_annotation 'Controller'
java_annotation 'RequestMapping("/welcome")'
class GreetingController
java_annotation 'RequestMapping'
java_signature 'String print(ModelMap model)'
def print(model)
model.add_attribute('greeting', 'Hello, World!')
"index"
end
end
(The full example can be found on github; the JRuby compiler is called by the jruby-maven-plugin
)
Upvotes: 1