سؤال

I'm trying to Play 2 application on Windows Server Server 2012 using the "stage" task, with the goal of wrapping this up in a service so the application will automatically run when the server gets restarted. However, when running the app I get the following message:

The input line is too long.
The syntax of the command is incorrect.

This is because Windows has a limit of around 8000 characters for command line instructions but it seems like the Play stage command is exceeding this by passing the classpath as an argument.

Copying the "stage" folder to c:\ might fix the issue (as it'll reduce the size of the classpath) but I was hoping there would be a more elegant solution.

Has anyone found a way around this? Alternatively, do people have any suggestions for running a Play application on Windows so that it will automatically run when the server is restarted.

Thanks.

هل كانت مفيدة؟

المحلول 2

UPDATE: sbt native packager now comes with a number of built in solutions to this, see NieMaszNic's answer below.

This is a known issue, being tracked in the SBT native packager (which generates the start script) here:

https://github.com/sbt/sbt-native-packager/issues/72

My recommendation to work around this issue would be to write your own start batch script that uses a wildcard classpath matcher. You can put this script in the dist directory in your Play project, and it will end up being packaged up with your application. That script might look like this:

java %1 -cp "./lib/*;" play.core.server.NettyServer .

Note that if you use a wildcard classpath matcher, you can no longer rely on classpath ordering to be the same as in dev mode. You shouldn't rely on classpath ordering anyway, but people inevitably do.

نصائح أخرى

I also had the same issue and I wasn't satisfied with the solutions that you provided.

I have found a simpler solution.

Add the following line to the build.sbt file

lazy val root = (project in file(".")).enablePlugins(PlayScala, LauncherJarPlugin)

Now if you generate your production application with:

sbt dist

or run a production mode with

sbt start

The LauncherJarPlugin plugin will take care for generating proper bash/batch run scrips.

To get to know more about LauncherJarPlugin please read the documentation:

Sbt documentation about long classpath

How to enable plugin in build sbt

Taking James's suggestions into account, the following solution works for a Play 2 application.

  • CD into the app and run play clean stage

  • Copy [your_app]/target/universal/stage/bin/[YOUR_APP].bat to [your_app]/dist (you may need to create the "dist" directory). I renamed the file as [your_app]_windows.bat to make it clear but the name doesn't really matter. Files in the "dist" directory get copied across with your app the next time you run the stage task (thanks James).

  • Open your new bat file in a text editor.

  • Files put in the "dist" directory are put in the "universal" directory (not "bin") so you'll need to change the home variable, i.e. remove the two full stops at the end so it doesn't navigate to the parent directory (on line 11 at present), e.g.

    if "%WEB_PORTAL_HOME%"=="" set "WEB_PORTAL_HOME=%~dp0\\.."

becomes:

if "%WEB_PORTAL_HOME%"=="" set "WEB_PORTAL_HOME=%~dp0"
  • You then need to change the class path, as per James's instructions, to use a wildcard rather than explicitly listing all the JAR files (at the moment this is on line 91) e.g.

    set "APP_CLASSPATH=%APP_LIB_DIR%\web-portal.web-portal-1.0-SNAPSHOT.jar;%APP_LIB_DIR%\commons-c.....

becomes:

set "APP_CLASSPATH=%APP_LIB_DIR%\web-portal.web-portal-1.0-SNAPSHOT.jar;%APP_LIB_DIR%\\*"
  • You can then run your new script (which is copied into the [your_app]/target/stage/universal directory).

Important: I'd recommend re-creating this file every time you upgrade

Play just in case the build script changes in future releases.

Change the longest line in your bat file with:

set "APP_CLASSPATH=%APP_LIB_DIR%\..\conf\;%APP_LIB_DIR%\*"

just before

set "APP_MAIN_CLASS=play.core.server.ProdServerStart"

Enable LauncherJarPlugin first

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, LauncherJarPlugin)

Then if you want just to start play with production mode you can use activator :

activator clean compile stage testProd 

or fast version :

activator testProd

This will run play in production mode, i'm not sure if you have to addstage to command because i'm pretty sure that its already building with testProd, but its better to make sure you built the stage version.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top