Use a specific Java path for Play! Framework

With an experimental goal in mind of creating a fully portable Play! application without worrying about whether the host has a Play! or even Java, I'm trying to find a way to tell Play! where to look for Java and not look at the JAVA_HOME environment variable.

Linking the structure itself to the application is not very difficult, and I even found a way to "embed" MySQL, but I did not find a way to link Java and make Play! use the JRE that I have in the same directory. Is it possible?

+4
source share
2 answers

How do you start to play? If you have not just added start.sh/start.bat, which will set JAVA_HOME to current_folder / jdk?

You can also pack the Play application as a WAR file and use it with a portable tomcat or other web server.

Description of the play command:

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

So, you can try adding Java / bin to your path or try adding “java” to your working directory, where you start playing.

As a last option, you can change play\framework\pym\play\application.py and add your path directly to it, change 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']) 
+7
source

In addition to @AlexanderPonomarenko's answer and @Indigenuity's comment (they both made sense), here is a workaround that works for me on Win7 x64 with Play 1.4.2:

I edited the play.bat file located in the root directory of the Play and installed its contents:

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

Please note that this works for my use with Java 8u112 x86, you must install it in the one you need.

Also note the syntax of the JAVA_HOME declaration, enclosed in double quotes due to spaces.

Enjoy :)

0
source

Source: https://habr.com/ru/post/1399245/


All Articles