Search code examples
playframeworkbundlejava

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?


Solution

  • 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'])