Loading a class from a jar

19 views
Skip to first unread message

aditya

unread,
Mar 1, 2013, 10:47:24 AM3/1/13
to scala...@googlegroups.com
Hey 

The problem is something like this:
I have a the name of the class which contains a function I want to run. When my app executes, I give it the name, and it searches through all jars in /extern-libs and tries to find the class. If this class is found, it creates an instance of this and runs the function.

Any ideas on how this can be accomplished?


Alex Cruise

unread,
Mar 1, 2013, 5:44:22 PM3/1/13
to aditya, scala-user
Here are a couple ways:

The old school way: http://docs.oracle.com/javase/1.4.2/docs/guide/jar/jar.html#Service Provider

I've also used Brian Clapper's ClassUtil: http://software.clapper.org/classutil/

-0xe1a




--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Flavio W. Brasil

unread,
Mar 1, 2013, 5:54:16 PM3/1/13
to Alex Cruise, aditya, scala-user

-- 
Flávio W. Brasil
{persistence as it should be}

Aditya Vishwakarma

unread,
Mar 1, 2013, 10:04:26 PM3/1/13
to Flavio W. Brasil, Alex Cruise, scala-user
Thanks. Are there any libraries which use 2.10 reflection ? 

Aditya Vishwakarma

Flavio W. Brasil

unread,
Mar 2, 2013, 10:12:01 AM3/2/13
to Aditya Vishwakarma, Alex Cruise, scala-user
I don't know if it is possible to scan jars using the scala 2.10 reflection.
To reflect the found classes you can use smirror.

-- 
Flávio W. Brasil
{persistence as it should be}

Reply all
Reply to author
Forward
0 new messages