[2.0.4-java] Getting classpath at runtime

2,084 views
Skip to first unread message

BreuJa

unread,
Oct 24, 2012, 10:12:10 AM10/24/12
to play-fr...@googlegroups.com
Hi all,

I'm having a hard time getting the classpath settings at runtime.

The usual suspect System.getProperty("java.class.path") just returns "/opt/play/current/framework/sbt/sbt-launch.jar".

Does anyone have an idea on how to get the classpath inside a play project? Every hint and every dirty hack is welcome.
I do not want to modify the classpath. I would like to start a separate Java-Process with the help of JavaProcessBuilder
( http://code.google.com/p/java-process-builder/ ).
However, what is missing by now is just the classpath setting, otherwise I get a NoClassDefFoundError.

Many thanks in advance & Kind regards
Jens

Mathias Clerc

unread,
Oct 24, 2012, 8:40:01 PM10/24/12
to play-fr...@googlegroups.com
Play is using a custom classloader (for runtime rebuild).
It can be accessed through the Application class:
http://www.playframework.org/documentation/api/2.0/java/play/Application.html

I don't know if JavaProcessBuilder and that classloader can be friends
(maybe only in dev mode)

2012/10/24 BreuJa <breue...@googlemail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/QdTawdTDiukJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

James Roper

unread,
Oct 25, 2012, 9:19:30 PM10/25/12
to play-fr...@googlegroups.com
Here is a StackOverflow thread that talks about exactly what you want to do


In prod, it should work with no problems.  In dev however, it's much more complex, the Play classloader is a series of URL classloaders, so to get the *entire* classpath you may need to walk up the Classloader tree using ClassLoader.getParent.

Also be careful in dev, when Play reloads, the old classloader will become invalid, in fact things in it will stop working very quickly, so make sure you implement the necessary Global.onStop to shut down any spawned processes, otherwise those processes won't be happy.

BreuJa

unread,
Nov 8, 2012, 4:53:05 PM11/8/12
to play-fr...@googlegroups.com
Hi James,

thank you so very much for your reply. That code just works for me right now as I need it.

Sorry for the late feedback but the flu struck me down lately.

Kind regards & Many thanks
Jens

Reply all
Reply to author
Forward
0 new messages