Indigenuity
Indigenuity

Reputation: 9740

Use specific Java path for Play! Framework

With the the experimental goal in mind of making a completely portable Play! application, without worrying about whether the host machine has Play! or even Java, I'm trying to find a way to tell Play! where to look for Java, rather than looking at the environment variable JAVA_HOME.

Bundling the framework itself with the application isn't very difficult, and I have even found a way to "embed" MySQL, but I haven't found a way to bundle Java and make Play! use the JRE I have in the same directory. Is this possible?

Upvotes: 4

Views: 6000

Answers (2)

Benj
Benj

Reputation: 1204

In complement to @AlexanderPonomarenko's answer and @Indigenuity's comment (they both got the point), here is the workaround that works for me on Win7 x64 with Play 1.4.2:

I edited the play.bat file located at Play's root, and setted its content to :

echo off
set "JAVA_HOME=C:\Program Files (x86)\Java\jre1.8.0_112"
"%~dp0python\python.exe" "%~dp0play" %*

Note that this works for my use case with Java 8u112 x86, you have to set it to what you need.

Also note the syntax for declaring the JAVA_HOME enclosed into double quotes because of the spaces.

Enjoy :)

Upvotes: 1

Alexander Ponomarenko
Alexander Ponomarenko

Reputation: 559

How are you starting Play? If you why not just add start.sh/start.bat that will set JAVA_HOME to current_folder/jdk?

You can also package your Play application as WAR file and use with portable tomcat or other web server.

Per Play command description:

~ The script first tries to locate the java command using the $JAVA_HOME environment variable (from $JAVA_HOME/bin). ~ If the $JAVA_HOME variable is not defined, the default java command available from the PATH is used.

So you can try to add Java/bin to your path, or try to add "java" to your working directory where you start play.

As a last option, you can modify play\framework\pym\play\application.py and add your path directly in it, modify this part:

   def java_path(self):
        if not os.environ.has_key('JAVA_HOME'):
            return "java"
        else:
            return os.path.normpath("%s/bin/java" % os.environ['JAVA_HOME'])

Upvotes: 7

Related Questions