4

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?

2 Answers 2

7

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'])
Sign up to request clarification or add additional context in comments.

2 Comments

I ended up pasting JDK 1.7 into Play 1.2.4, and pasting that into my project. Never done a bat before, so it was tricky to figure out the path from a .bat file, but I just stuck this line in play.bat: set JAVA_HOME=%~dp0\jdk1.7.0
And Thank you very much for pointing out where I could change the python code. VERY instructive. I was using that solution at first, but I decided changing the play.bat was a safer, more portable method.
1

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.