Play Framework 2 Stage Task on Windows, “The input line is too long”

心已入冬 提交于 2019-11-28 09:01:24

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

Ian

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.

Mrc Bdl

Change the longest line in your bat file with:

set "APP_CLASSPATH=%APP_LIB_DIR%\..\conf\;%APP_LIB_DIR%\ *"
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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!