difference between Groovy JDK API Documentation and groovy api Documentation - groovy

I am new to groovy I want to know the exact difference between Groovy JDK API Documentation and groovy api Documentation. I want to know the purpose of those api

Groovy adds additional methods to some JDK library classes (e.g String, File). These additional methods are known as the Groovy JDK and are documented here. All the methods that are available when using JDK classes in a Java program are also available when using them from a Groovy program.

Related

How to import or load cryptojs in groovy scripting?

I am doing groovy scripting in ReadyAPI tool for API automation, i need to do 'CryptoJS.enc.Base64.parse("secretkey") .
But it says 'CryptoJs' not defined. Can any one help me on this?
I have already added 'crypto-js-3.1.9-1' jar file in readyapi bin/ext folder.
CryptoJS (from https://www.webjars.org/ I guess) is a JavaScript library - not Groovy.
You can't execute JavaScript code directly in groovy.
There are crypting algorithms supported natively in java/groovy. Just search by algorithm name + java.
I know that readyapi supports rhino javascript as scripting language, but i'm not sure it's possible to import external javascript libraries..

When to do Nashorn over Java Hooks?

I have a java application that does text processing.
Nashorn could be used to add customization just like hooks. So When should I use Nashorn and when should I use hooks? (assuming language doesn't matter)
It should be possible to write your hooks assuming java lambdas. This would allow Nashorn functions or Java functions to be used for your hooks. If you direct your question to nashorn-dev with specifics you will get more specific details.

Cannot call Java newInstance() instead of Groovy's When Running Compiled Groovy Code in Mule ESB

Inside my Mule ESB 3.3.0 app, running in standalone mode, I have a transformer that calls Groovy code that is included as a maven dependent jar. In my groovy code, I am calling a Java object that has a newInstance() static method, like so:
TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null)
This is causing errors in Groovy because I think its trying to call the Groovy enhanced Class.newInstance() method. This does not happen when running outside Mule standalone (see update below for description of test). How can I make it call the Java method and not the Groovy one?
Here is a snippet of my stack trace. You can see its calling DefaultGroovyMethods.newInstance(). But I want to call the javax.xml.transform.TransformerFactory.newInstance(String, ClassLoader) method instead. How?
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: javax.xml.transform.TransformerFactory(java.lang.String, null)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1459)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1375)
at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.newInstance(DefaultGroovyMethods.java:18025)
UPDATE:
More info about the runtime environment. The Groovy code is packaged as a jar file and called from a Mule ESB app. Mule 3.3.0 ships with groovy-all-1.8.6.jar.
UPDATE2:
I did some further tests and compiled a Groovy class into a jar file and called it from a standalone Java program and did not experience this issue. This leads me to believe that it is an issue running from the Mule 3.3.0 standalone environment. I am adding a mule tag to this post. Hopefully a Mule expert can tell me what is going on.
With some help from the Groovy user mailing list, we determined that there must be another jar on the mule classpath that is providing the javax.xml.transformer.Transformer class. I added this sample code:
Class klass = TransformerFactory.class;
URL location = klass.getResource('/'+klass.getName().replace('.', '/')+".class");
And sure enough! Mule is adding their own XML API jar.
TranformerFactory JAR: jar:file:/D:/java/mule/mule-standalone-3.3.0/lib/endorsed/xml-apis-1.3.04.jar!/javax/xml/transform/TransformerFactory.class
Why are you overriding the JDK Mule?
My work around was to instantiate the Saxon TransformerFactory directly. Its not very elegant, but my only option.
tFactory = new net.sf.saxon.TransformerFactoryImpl()

hibernate like technology as a persistence layer for groovy?

I was wondering if there is like a persistence layer for groovy that is integrated on the ide to generate code automatically based on your database structure?
Just use Hibernate, as you would for a Java project.
Groovy can call java, and you can use the cross-compiler to compile both sources when you build your project.
The Hibernate tools will not spit out Java (so the code will be more verbose than the Groovy replacements), but as you won't need to write the code, this doesn't matter ;-)

Use JAXB-RI with Jersey

I am using the xjc ant task provided by the JAXB-RI to generate our jaxb classes and provide all the jaxb jars in with my web application's WEB-INF/lib folder. Jersey is still using the runtime provided jaxb implementation (found in rt.jar) Is there some way to use #Provider to force it to use the jaxb-ri jars?
As far as I understood the problem correctly, this small tutorial should help.

Resources