Groovy cannot call Classloader (NullpointerException)
I have created the following Groovy Script to transform an JSON Document
with a Java Library. But somehow I am not able to load the class from a
jar that I need. I always get java.lang.ClassNotFoundException:
de.is24.gis.geotools.CoordinateTransformer
The Jar file is in the same directory like the groovy script. I can not
edit the way I call the groovy script. It is called automatically by a
river.
import groovy.json.JsonSlurper
geo = new GeoTransformer()
geo.transform(ctx.document)
class GeoTransformer {
void transform(doc) {
this.getClass().classLoader.addURL(new
File("gis-geotools-1.9.0.jar").toURL())
def CoordinateTransformer =
Class.forName("de.is24.gis.geotools.CoordinateTransformer").newInstance();
def x =
doc.realEstateCommonData.locationDto.geoCoordinateDto.xCoordinate;
def y =
doc.realEstateCommonData.locationDto.geoCoordinateDto.yCoordinate;
def coords = CoordinateTransformer.transformFromLambertEuToWgs84(x,z)
println coords.getLatitude()
println coords.getLongitude()
def jsonObj = new JsonSlurper().parseText( '{"type" : "Point",
"coordinates" : [' + coords.getLatitude() + ',' +
coords.getLongitude() + ']}' )
doc.location = jsonObj
}
}
No comments:
Post a Comment