Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Play! to RePlay migration] play.exceptions.UnexpectedException: Failed to read $PWD/conf/application.conf at startup #198

Closed
xabolcs opened this issue Jun 26, 2023 · 5 comments · Fixed by #291 or #375

Comments

@xabolcs
Copy link
Collaborator

xabolcs commented Jun 26, 2023

From the codeborne/replay gitter.im channel:

@xabolcs wrote:

my problem is that it doesn't find the application.conf also the play.plugins in the conf/ directory ... of course as the default play.PropertiesLoader uses the current dir: ./conf/

Using the application plugin (id: 'application') and running the extracted application from the build/distributions/app dir:

$ ./bin/app
Exception in thread "main" play.exceptions.UnexpectedException: Failed to read /app/build/distributions/app/conf/application.conf
	at play.vfs.VirtualFile.inputstream(VirtualFile.java:106)
	at play.libs.IO.readUtf8Properties(IO.java:17)
	at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:42)
	at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:32)
	at play.PropertiesConfLoader.readConfiguration(PropertiesConfLoader.java:28)
	at play.Play.readConfiguration(Play.java:258)
	at play.Play.init(Play.java:154)
	at com.openseedbox.Application.start(Application.java:23)
	at com.openseedbox.Application.main(Application.java:32)
Caused by: java.io.FileNotFoundException: /app/build/distributions/app/conf/application.conf (No such file or directory)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
	at play.vfs.VirtualFile.inputstream(VirtualFile.java:104)
	... 8 more

@xabolcs wrote:

how hard would be to modify PropertiesConfLoader to allow implementing a PropertiesConfLoaderFromResources?
is play.vfs.VirtualFile classpath aware? is able to work with(in) jars?

@asolntsev wrote:

Sure, it's always a good idea to load resources from classpath. I think it should be easy.


It would be nice if the RePlay framework would be able to resolve the conf/ directory through the classpath in the case it doesn't exists in the working directory. In that case it would be easy to add conf/ dir to the classpath through the sourceSets.main.resources. The following example fills the resources build directory without defining resources in the project:

// snip

sourceSets {
  main {
    java {
      srcDir "app"
      exclude 'views/'
    }
    resources {
      // no need to define anything
    }
  }
}

// snip

processResources {
  from('conf') {into 'conf'}
  from('app') {include 'play.plugins'}
  from('app/views') {into 'app/views'}
  from('public') {into 'public'}
}
@xabolcs xabolcs changed the title [Play! to RePlay migration] play.exceptions.UnexpectedException: Failed to read $PWD/conf/application.conf [Play! to RePlay migration] play.exceptions.UnexpectedException: Failed to read $PWD/conf/application.conf at startup Jun 26, 2023
@asolntsev asolntsev added this to the 2.2.0 milestone Jun 26, 2023
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Jun 27, 2023
…framework#198)

in case when they don't exits in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker) the working
directory doesn't always contain the conf/ directory, but the classpath.
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Jun 27, 2023
…framework#198)

in case when they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker) the working
directory doesn't always contain the conf/ directory, but the classpath.
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Jun 27, 2023
…framework#198)

in case when they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker) the conf/
directory doesn't always exists in the working directory, but in the
classpath.
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Jul 4, 2023
…framework#198)

in case when they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker) the conf/
directory doesn't always exists in the working directory, but in the
classpath.
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Aug 18, 2023
…framework#198)

in case when they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker) the conf/
directory doesn't always exists in the working directory, but in the
classpath.
@asolntsev asolntsev modified the milestones: 2.2.0, 2.3.0 Sep 29, 2023
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Sep 30, 2023
…framework#198)

in case when they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker)
the conf/ directory doesn't always exists in the working directory,
but in the classpath.

Fixes: replay-framework#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Sep 30, 2023
…-framework#198)

in case they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker)
the conf/ directory doesn't always exists in the working directory,
but in the classpath.

Fixes: replay-framework#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Oct 14, 2023
…-framework#198)

in case they don't exists in the working directory.

Running RePlay apps in a distributed form (zip, tar, docker)
the conf/ directory doesn't always exists in the working directory,
but in the classpath.

Fixes: replay-framework#198
asolntsev added a commit that referenced this issue Nov 21, 2023
…l file)

it allows users to extract route files to modules (a jar file added to the project as a dependency).
@asolntsev asolntsev linked a pull request Nov 21, 2023 that will close this issue
asolntsev added a commit that referenced this issue Nov 22, 2023
…ly from local file)

it allows users to extract conf files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Nov 22, 2023
…ng templates

* Now `Play.appRoot` has type `File`
* `Play.applicationPath` was removed because it's the same as `Play.appRoot`
asolntsev added a commit that referenced this issue Nov 22, 2023
…ocal file)

it allows users to extract template files to modules (a jar file added to the project as a dependency).
@asolntsev asolntsev modified the milestones: 2.3.0, 2.3.1, 2.4.0 Dec 16, 2023
@xabolcs
Copy link
Collaborator Author

xabolcs commented Jan 4, 2024

I created an example repo to describe my problems: Example project for RePlay! issue #198

It's still in progress, but one could play with

  • ./gradlew clean run
  • ./gradlew clean distTar jibDockerBuild
    • untar the *.tar from build/distributions/ and try to run it
    • docker run --rm -ti replay-example:issue-198

@asolntsev
Copy link
Contributor

@xabolcs I tried to clone the repo.

  1. Command ./gradlew clean run starts, but when I open http://localhost:9000/ in my browser, it causes errors:

    Template not found : /tmp/errors/404.html
    Template not found : /tmp/errors/500.html

  2. Command docker run ... throws FileNotFoundException: /conf/application.conf, but when I look into the docker image, I see that it actually doesn't contain folder conf and file application.conf.

@xabolcs
Copy link
Collaborator Author

xabolcs commented Jan 8, 2024

Thanks for looking into it. It's still in "development" 😅

For the 1. point, it related to #65 (and it's related issues) - I didn't care much for using the empty sample app.
For the 2. point ... well yeah.

The example repo is at a decision point when one have to choose how deal with the old/current behavior - RePlay framework searches $PWD/conf/application.conf at startup ... exaclty what the title of this issue says.

One way to solve this is to "fix" the distribution tasks (the application, the jib, ...) without defining the conf dir as a resource (or even mention it in the processResources task): just do extra steps to copy conf directory in the distribution's working directory - which is isn't easy with dist but very straightforward with jib.

The other way to solve this is to teach the RePlay framework to check not the conf/ folder in the current working directory but to check the conf/ path on the classpath too. Then the solution would be just as easy as creating the conf/ directory in the resources:

So I didn't choose a workaround yet because it could influence the fix itself.

@asolntsev
Copy link
Contributor

@xabolcs It's much simpler than you think.
Take a look at the sample app ("criminals"). It has exactly the same folders' structure as the original Play! projects:
image

And everything you need to make Gradle support these folder is this piece in build.gradle:

sourceSets {
  main {
    java {srcDir "app"}
    resources {srcDir "app"}
    resources {srcDir 'conf'}
  }
  test {
    java {srcDir "test"}
  }
}

@xabolcs
Copy link
Collaborator Author

xabolcs commented Jan 9, 2024

It's much simpler than you think.

I thought I tried this "define the app both as java source and resource" thing and my IDEA didn't like it. Sure will retest!
Thanks.

asolntsev added a commit that referenced this issue Jan 21, 2024
…l file)

it allows users to extract route files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Jan 21, 2024
…ly from local file)

it allows users to extract conf files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Jan 21, 2024
…ng templates

* Now `Play.appRoot` has type `File`
* `Play.applicationPath` was removed because it's the same as `Play.appRoot`
asolntsev added a commit that referenced this issue Jan 21, 2024
…ocal file)

it allows users to extract template files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Jan 21, 2024
…l file)

it allows users to extract route files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Jan 21, 2024
…ly from local file)

it allows users to extract conf files to modules (a jar file added to the project as a dependency).
asolntsev added a commit that referenced this issue Jan 21, 2024
…ng templates

* Now `Play.appRoot` has type `File`
* `Play.applicationPath` was removed because it's the same as `Play.appRoot`
asolntsev added a commit that referenced this issue Jan 21, 2024
…ocal file)

it allows users to extract template files to modules (a jar file added to the project as a dependency).
xabolcs added a commit to xabolcs/openseedbox-common that referenced this issue Apr 23, 2024
Re-Play 2.4.0
- bumped Java requirement to 17
- moved from group 'com.codeborne.replay' to 'io.github.replay-framework'
- started to require 'application.conf' being on the classpath

For the latter see replay-framework/replay#198
xabolcs added a commit to openseedbox/openseedbox-common that referenced this issue Apr 23, 2024
Re-Play 2.4.0
- bumped Java requirement to 17
- moved from group 'com.codeborne.replay' to 'io.github.replay-framework'
- started to require 'application.conf' being on the classpath

For the latter see replay-framework/replay#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Apr 24, 2024
Modify "multi-module-app" test to use the "conf/" directory:
- conf/application.conf
- conf/routes

To achieve this let move the "conf/" directory (which location is
defined in replay-tests.gradle) to the default resources location:
"src/main/resources/".

With this change these files would be at classpath
"conf/application.conf" and "conf/routes", NullPointerException:

HelloWorldSpec > openHelloWorldPage() FAILED
    java.lang.NullPointerException: File not found in classpath: application.conf
        at java.base/java.util.Objects.requireNonNull(Objects.java:336)
        at play.ClasspathResource.<init>(ClasspathResource.java:42)
        at play.ClasspathResource.file(ClasspathResource.java:26)
        at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:34)
        at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:30)
        at play.PropertiesConfLoader.readConfiguration(PropertiesConfLoader.java:26)
        at play.Play.readConfiguration(Play.java:230)
        at play.Play.init(Play.java:138)
        at play.server.Starter.start(Starter.java:19)
        at hello.HelloWorldApp.start(HelloWorldApp.java:7)
        at ui.hello.BaseSpec.startApp(BaseSpec.java:23)
        at ui.hello.BaseSpec.setUp(BaseSpec.java:17)

Ref: replay-framework#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Apr 24, 2024
to ease migration from Play1 projects.

Modify "multi-module-app" test to work from "conf/" directory:
- use "conf/application.conf" for configuration
- use "conf/routes" for routes

This is an advanced setup, so play.server.Starter couldn't help.

While at it, fix README about Criminals example project.

Ref: replay-framework#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Apr 24, 2024
Modify "multi-module-app" test to use the "conf/" directory:
- conf/application.conf
- conf/routes

To achieve this let move the "conf/" directory (which location is
defined in replay-tests.gradle) to the default resources location:
"src/main/resources/".

With this change these files would be at classpath
"conf/application.conf" and "conf/routes", causing NullPointerException

HelloWorldSpec > openHelloWorldPage() FAILED
    java.lang.NullPointerException: File not found in classpath: application.conf
        at java.base/java.util.Objects.requireNonNull(Objects.java:336)
        at play.ClasspathResource.<init>(ClasspathResource.java:42)
        at play.ClasspathResource.file(ClasspathResource.java:26)
        at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:34)
        at play.PropertiesConfLoader.readOneConfigurationFile(PropertiesConfLoader.java:30)
        at play.PropertiesConfLoader.readConfiguration(PropertiesConfLoader.java:26)
        at play.Play.readConfiguration(Play.java:230)
        at play.Play.init(Play.java:138)
        at play.server.Starter.start(Starter.java:19)
        at hello.HelloWorldApp.start(HelloWorldApp.java:7)
        at ui.hello.BaseSpec.startApp(BaseSpec.java:23)
        at ui.hello.BaseSpec.setUp(BaseSpec.java:17)

Ref: replay-framework#198
xabolcs added a commit to xabolcs/re-play1 that referenced this issue Apr 24, 2024
to ease migration from Play1 projects.

Modify "multi-module-app" test to work from "conf/" directory:
- use "conf/application.conf" for configuration
- use "conf/routes" for routes

This is an advanced setup, so play.server.Starter couldn't help.

While at it, fix README about Criminals example project.

Ref: replay-framework#198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment