Play Framework 2 Stage Task on Windows, "The input line is too long"
Asked Answered
P

5

27

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.

Pickel answered 29/1, 2014 at 11:7 Comment(0)
C
20

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.

Craving answered 29/1, 2014 at 13:28 Comment(2)
That worked great. I'll create a separate answer which explains specifically how to get this working with a Play 2 application. Thanks for your help.Pickel
Am getting error as below Error: Could not find or load main class play.core.server.NettyServerPlacard
F
24

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

Fong answered 21/3, 2016 at 13:22 Comment(4)
plus one for being lazy :)Perilous
For java it is lazy val root = (project in file(".")).enablePlugins(PlayJava, LauncherJarPlugin)Blowbyblow
Still a problem in playframework-2.5 with sbt.version=0.13.8. Adding `LauncherJarPlugin fixes the problem.Dittography
Thanks. you saved my times.Ardussi
C
20

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.

Craving answered 29/1, 2014 at 13:28 Comment(2)
That worked great. I'll create a separate answer which explains specifically how to get this working with a Play 2 application. Thanks for your help.Pickel
Am getting error as below Error: Could not find or load main class play.core.server.NettyServerPlacard
P
12

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.

Pickel answered 29/1, 2014 at 16:57 Comment(0)
C
2

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"
Crash answered 11/9, 2016 at 17:21 Comment(2)
And make sure the line is removed not just commented with a rem in front of it like I did. Issue still present in playframework-2.5.Dittography
watch for space between %APP_LIB_DIR%\ and *. It should be %APP_LIB_DIR%\* i.e. no spaceStove
M
0

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.

Manuel answered 31/5, 2016 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.