Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding external folder in the Play classpath

I'm a Play framework & SBT newbie.

In my Play for Java project, in one of the class, I need to read property files outside my Play application using ResourceBundle.getBundle().

I'm already able to do that in "Play Console" mode by adding the following in my build.sbt unmanagedClasspath in Runtime += file("/mybundle")

As I need to run the application in "Production" mode, I tried to do play dist, then unzip the zipped file, then went to the "bin" then run the generated shell script in the bin folder.

I found out that my class failed to read the bundle. (which is just fine in "Play Console" mode). Then I noticed that in the generated shell script to run the play, there is the following

declare -r app_classpath="$lib_dir/com.foo.abc-web-1.0-SNAPSHOT.jar:$lib_dir/com.foo.abc-common-1.0-SNAPSHOT.jar

I modify that line to add my folder so it'll become

declare -r app_classpath="/mybundle:$lib_dir/com.foo.simpleproject-web-1.0-SNAPSHOT.jar:$lib_dir/com.foo.abc-common-1.0-SNAPSHOT.jar

then restart my play application using the shell script, and my application can read the bundle correctly.

However, above work must be done manually and I'd like to externalize it.

What I'm trying to resolve are the following:

  1. Is there any way so the bundle folder which I specify in my build.sbt can be reused in play dist?

  2. Or if above is not possible, during play dist, is there any way to specify so my folder (i.e. "/mybundle") would be added to the app_classpath as above?

  3. Is there any way to externalize my folder in my build.sbt in the "Play console" mode?

BTW I also have tried to append -classpath when calling the script file, i.e ./simpleproject -classpath "/mybundle" however it generate "Bad application path: -cp" error. Same case when I replace -classpath with -cp.

Can anyone please give advise on above?

like image 625
Simon2014 Avatar asked Mar 28 '14 11:03

Simon2014


1 Answers

Is including them in the distribution an option? If so, just do this:

unmanagedResourceDirectories in Compile += file("/mybundle")

Apart from that, no, SBT native packager, which generates the start script, doesn't give you that flexibility. But you can write your own start script, put that in dist/bin/my-start-script.sh in your project, and it will end up in the bin directory of your distribution, and then you can use that. An easy way to ensure the classpath is correct would be to use wildcard classpaths, ie:

libdir=...
java -classpath "/mybundle:$libdir/*" ...
like image 180
James Roper Avatar answered Sep 30 '22 03:09

James Roper