Reflection and ClassLoader

Hello,
In a previous post to this forum, I've explained that I have an interpreter for my DSL that works on MPS.
At that time I've managed to dynamically load Java classes with some of the behaviour I have on my DSL (see Invoke a Java class by name).
I now have more complex Jars that have dependencies and, using the same method, I would find several ClassNotFoundExceptions.
To circumvent what seems to be a ClassPath bug on MPS (3.1.2.) and avoid adding all dependent Jars to my MPS project, uber Jars were created (with all detected dependencies) and I've added those to the project.
However this was not enough and it now seems that it's a ClassLoader problem (I have ClassCastExceptions). Is there anyone who managed to use reflection here?


Sérgio Ribeiro
Portugal
1 comment
Ok. I've managed to get it right.
The problem was at the uber jar creation: as several jars have same-named resources in the same relative location, some were being overwritten which caused problems at runtime.
To reate the uber jar I'm using the "maven-shade-plugin"; what I've done was to add some transformers (as found in the documentation at http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html).
This way, everything worked well at runtime.

Sérgio Ribeiro
Portugal.
0

Please sign in to leave a comment.