earldouglas / sbt-war

Package and run .war files with sbt
BSD 3-Clause "New" or "Revised" License
382 stars 105 forks source link

sbt-war.g8 template doesn't work as advertised #996

Closed dylemma closed 1 week ago

dylemma commented 1 week ago

I was planning to give the updated plugin a spin, so I generated a "hello world" app from the earldouglas/sbt-war.g8 template. When I run warStart it shows

sbt:hello-sbt-war> warStart
[info] [sbt-war] Starting server
[success] Total time: 1 s, completed Nov 15, 2024, 4:26:50 PM

But the server does not appear to actually be running:

curl: (7) Failed to connect to localhost port 8080 after 2231 ms: Could not connect to server

image

sbt:hello-sbt-war> test
[error] Test mypackage.MyServletSuite.getRoot failed: java.lang.Exception: port8080 should be open, took 5.491 sec
[error]     at http.Request$.awaitOpen(http.scala:33)
[error]     at http.Request$.apply(http.scala:47)
[error]     at mypackage.MyServletSuite.getRoot(MyServletSuite.scala:22)
[error]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]     at java.lang.reflect.Method.invoke(Method.java:566)
[error]     ...
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]         mypackage.MyServletSuite
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 6 s, completed Nov 15, 2024, 4:37:44 PM

OS: Windows 11 Java: 11

earldouglas commented 1 week ago

Thanks for the report! I'll see if I can reproduce this in Windows.

earldouglas commented 1 week ago

Does making the forked JVM's output noisier give any interesting clues?

You can do this by either of the following:

then run warStart again.

earldouglas commented 1 week ago

I tested this on Windows 10 with Java 17, and it looks like sbt-war is hosing the backslashes in Windows directory paths:

sbt:my-web-project> warStart
sbt:my-web-project> The specified path "C:UsersJamesDesktopmy-web-project       argetscala-3.1.0my-web-project_3-0.1.0-SNAPSHOT.war" does not exist.
sbt:my-web-project> show package
[info] C:\Users\James\Desktop\my-web-project\target\scala-3.1.0\my-web-project_3-0.1.0-SNAPSHOT.war

The war.properties file looks OK at first, but I think those single-backslashes need to be double-backslashes:

port=8080
warFile=C:\Users\James\Desktop\my-web-project\target\scala-3.1.0\my-web-project_3-0.1.0-SNAPSHOT.war

This might be the fix: https://stackoverflow.com/questions/5784895/java-properties-backslash

earldouglas commented 1 week ago

Reopening this until we get sbt-war.g8 updated and verify the fix.

earldouglas commented 1 week ago

The fix is released in sbt-war version 5.0.0-M6. sbt-war.g8 has been updated accordingly.

Please give it a try by either updating your project's project/plugins.sbt to point to sbt-war 5.0.0-M6, or by re-running sbt new earldouglas/sbt-war.g8 to create a new project.

Note that to run the tests, you must first start the server:

$ sbt
> warStart
> test
dylemma commented 1 week ago

Confirmed fixed, thank you!

sbt:hello-sbt-war> test
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 6 s, completed Nov 18, 2024, 9:27:15 AM

image