[JAVA] If the submodule assets are not found in the Play Framework

TL; DR

If you don't know the asset path in Play Framework sbt "show playAllAssets" Is super convenient

sizer@sizle:~/hello-play-assets (master *+>)
$ sbt "show playAllAssets"
[info] Loading global plugins from /Users/sizer/.sbt/1.0/plugins
[info] Loading settings for project hello-play-assets-build from plugins.sbt ...
[info] Loading project definition from /Users/sizer/hello-play-assets/project
[info] Loading settings for project root from build.sbt ...
[info] Loading settings for project child from build.sbt ...
[info] Set current project to hello-play-assets (in build file:/Users/sizer/hello-play-assets/)
[info] child / playAllAssets
[info] 	List((public/,/Users/sizer/hello-play-assets/child/target/web/public/main))
[info] playAllAssets
[info] 	List((public/,/Users/sizer/hello-play-assets/target/web/public/main))
[success] Total time: 0 s, completed 2019/05/20 19:36:09
###
#You can see a list of asset paths. target/web/public/It seems to be in main.
###
$ tree target/web/public/main/
target/web/public/main/
├── images
│   └── favicon.png
├── javascripts
│   └── main.js
├── lib
│   └── child
│       ├── images
│       │   ├── favicon.png
│       │   └── image_in_child.jpg
│       ├── javascripts
│       │   └── main.js
│       └── stylesheets
│           └── main.css
└── stylesheets
    └── main.css

8 directories, 7 files
###
# lib/{moduleName}/It seems that you can get it if you specify it in images
###

background

I am developing a web application with Play Framework (Java). The common parts are cut out into child modules. I want to call an asset in a child module. → I can't find it ...

├── build.sbt
├── child #=>This is the common part
│   ├── build.sbt
│   ├── app
│   ├── conf
│   └── public #=>Put the image here
├── conf
│   ├── application.conf
│   ├── logback.xml
│   └── routes
├── project
│   ├── build.properties
│   ├── plugins.sbt
└── public
    ├── images
    ├── javascripts
    └── stylesheets

`

Read the official documentation

When you package your application, all assets for the application, including all sub projects, are aggregated into a single jar How are public assets packaged? - playframework.com

It will make a jar file including subprojects. Yeah

Put it in the public folder and access it with ʻAssets.at (file: String) or ʻAssets.versioned (path =" / public ", file: Asset).

→ I'm addicted to not being able to access

Catch the official ISSUE

I found an ISSUE that can't read the assets of the child module!

Did you add the sbt web plugin or the play plugin (which transitively adds the sbt web plugin) to the subproject? Assets are now no longer considered classpath resources ... If you add the play plugin, you can put assets in the assets directory or the public directory. If you add the sbt web plugin, then you'll have to add the assets to the default directories for sbt-web, src/main/assets or src/main/public. https://github.com/playframework/playframework/issues/2944#issuecomment-44243541

Did you add the sbt-web plugin or the play plugin to the child module? Otherwise assets will not enter the classpath

(Write that in the documentation ...)

If you add the play plugin, you can put assets in the assets directory or the public directory. If you add the sbt web plugin, then you'll have to add the assets to the default directories for sbt-web, src/main/assets or src/main/public. https://github.com/playframework/playframework/issues/2944#issuecomment-44243541

If you put in the play plugin, read the assets or public directory. For the sbt-web plugin, it's src / main / assets or src / main / public.

(That's in the documentation ...)

Could you run show play-all-assets, and see if the assets are in there? Also useful may be to run show childproject/play-prefix-and-assets, and see if the child project assets are in there. https://github.com/playframework/playframework/issues/2944#issuecomment-44359790

If you run show play-all-assets, you will find the location of assets in the child project.

(That kind of thing is a document ...)

Executed

By the way

- show play-all-assets
+ show playAllAssets

was

sizer@sizle:~/hello-play-assets (master *+>)
$ sbt "show playAllAssets"
[info] Loading global plugins from /Users/sizer/.sbt/1.0/plugins
[info] Loading settings for project hello-play-assets-build from plugins.sbt ...
[info] Loading project definition from /Users/sizer/hello-play-assets/project
[info] Loading settings for project root from build.sbt ...
[info] Loading settings for project child from build.sbt ...
[info] Set current project to hello-play-assets (in build file:/Users/sizer/hello-play-assets/)
[info] child / playAllAssets
[info] 	List((public/,/Users/sizer/hello-play-assets/child/target/web/public/main))
[info] playAllAssets
[info] 	List((public/,/Users/sizer/hello-play-assets/target/web/public/main))
[success] Total time: 0 s, completed 2019/05/20 19:36:09
$ tree target/web/public/main/
target/web/public/main/
├── images
│   └── favicon.png
├── javascripts
│   └── main.js
├── lib
│   └── child
│       ├── images
│       │   ├── favicon.png
│       │   └── image_in_child.jpg
│       ├── javascripts
│       │   └── main.js
│       └── stylesheets
│           └── main.css
└── stylesheets
    └── main.css

8 directories, 7 files

ʻAssets.at ("lib / child / images / youfile.jpg) `was in the place.

What is lib / {moduleName}, please write such a thing in the document!

Impressions

Unfriendly framework of official documentation Seriously: poop:

PS

I made ISSUE with lib / {moduleName} as a prefix. : thumbsup: please It may be appropriate to put it on sbt-web, but please let me know who you are.

https://github.com/playframework/playframework/issues/9331

Recommended Posts

If the submodule assets are not found in the Play Framework
If the submodule assets are not found in the Play Framework
Spring-Boot main class not found
HttpServletRequest class file not found
Check if Ethereum transactions are not included in the block
What to do if the changes are not reflected in the jar manifest file
Line breaks in the entered text are not displayed in view
Memo that transitions to the login screen if you are not logged in with devise
Validation function in Play Framework
What to do when the changes in the Servlet are not reflected
Determine if the strings to be compared are the same in Java
Error in ./gradlew: Symbol not found
What are the rules in JUnit?
What to do if the prefix c is not bound in JSP
Authentication function in Play Framework [Access restrictions]
must not return in the for statement
Play Framework 2.6 (Java) environment construction in Eclipse
Add if not in Set, error message if
If the ctrl + shortcut does not work in Eclipse, disabling welcome may help
When I run the source command in the Ubuntu Makefile, it says "source: command not found"