Spring boot alternate src/main/resource directory on classpath - resources

This post is not about serving static resources in Spring Boot. There are other posts that cover that nicely. I think I have a grasp now of the different /public /static directory options, whether located underneath src/main/resources or not. What I want to know is whether I can specify an additional directory in my project whose contents will also be placed at the root of the classpath (as opposed to the web document root).
Specifically, I am referring to my translated resource bundles (e.g., index.properties, index_fr.properties, index_de.properties, etc.). In my pre-Spring Boot projects I have a "bundles" directory designated for all my translated property files. I would prefer to continue using a bundles directory for my translated strings and not have to place them in my src/main/resources directory with the main application property files.

Related

Play! 2.3.x Customizing build.sbt for Linux (ubuntu server) production distribution

In a previous question I wondered how to prevent conf files to be packaged inside zip distribution file (actually, inside the app jar itself), since the same set of conf files are packed as <app zip>/conf. When the package is installed (unzipped) in the server, conf files are both visible and accessible to be modified, but hidden by the packed copies inside the jar.
There is a simple way to address these exposed conf files, by passing Dconfig.resoure cl param (ei,Dconfig.resoure=conf/application.conf), but I think the duplicity of conf files as mentioned is confusing.
So, I'm looking for some build.sbt customization to accomplish:
prevent including conf files in app jar (unless someone can explain me why is this the default procedure, maybe I'm missing something here)
prevent including certain files in assets jar (ei, public/javascript/exclude-me/*), but include them in zip file in order to be accessible for customization in the production server (when unzipped, just like the mentioned conf files)

Linux Folder/Package Management

I'm looking for a way to store all my applications files within a single folder. However, when someone clicks on the folder I want the application inside the folder to open up as opposed to open the folder itself. I want to keep all dependancies and files inside this folder at all times.
I'm doing this because I'm going to be deploying a couple applications on a common framework and want to ensure that they are together and independent of the distribution have all requirements.
Folders are directories, and directories are distinct from files. There's no way to redirect a directory to an executable file. However, you can make a hidden directory (begin name with ".") and use an executable file to provide access to that directory. The directory will then not appear in window manager folders, just the application. However, window managers will not misrepresent the executable file as a directory.

About Maven resources

From the stand point of a Maven project, should files stored there be accessed in any special way or be treated as any other file where "resources" is just another directory?
What makes this directory special? Is it fair to say that "resource" is anything that is not a source file and that is used by a program?
I am a bit confused here. Please clarity
All files in the resources directory get added to your jar (or war) without being compiled. Generally things like config files or other non-source resources are put in this directory, although as long as your files don't end in ".java" they could live in the sources directory and the resulting artifact would be the same.
To access a file in the resources directory you would use the ClassLoader.getResource or getResourceAsStream methods.
The other feature of resources when using Maven is that you can include property tokens that will be replaced by Maven as part of building your project. For instance:
This line in a resource file
artifactName=${project.build.finalName}
Would be replaced with something like:
artifactName=my-project-1.0.0
Any of the properties available within Maven can be replaced in your resources.
It's just a standard. By default, the contents of the resources directory are copied to the same target directory as the .class files and, if packaged as a jar, in the root of the jar.
You can also specify how resources are encoded. If you don't, you effectively preserve the encoding of the system on which you built, which is non-portable and is something Maven will warn you about.

Access file in weblogic server

Is there a folder in the Domain Directory of Weblogic, where files put inside can be accessed directly from web browser? In other word, I don't have to pack the file in an ear, war file and deploy it to make it accessible?
Thank you very much
Regards
K.
The Virtual Directory Mapping feature (that you declare in the weblogic.xml) would do the trick:
Using the virtual directory mapping
feature, you can create one directory
to serve static files such as images
for multiple Web Applications. For
example, you would create a mapping
similar to the folowing:
<virtual-directory-mapping>
<local-path>c:/usr/gifs</local-path>
<url-pattern>/images/*</url-pattern>
</virtual-directory-mapping>
A request to
http://localhost:7001/mywebapp/images/test.gif
will cause your WebLogic Server
implementation to look for the
requested image at:
c:/usr/gifs/images/*.
This directory must be located in the
relative uri, such as
"/images/test.gif".

How to host multiple webapps using only 2 Virtual Directories

my shared hosting only allows me to create 2 virtual directories. and i want to host multiple webapps... say an asp.net mvc blog, a forum, a personal site etc...
isnt there any other way of doing this? cant i simply just ftp the blog folder to one of my virtual directories and then access it online??
For ASP.NET web applications, typically each would live in its own virtual directory which serves as the application starting point.
Technically you could "piggy-back" two applications on the same application starting point in one of two ways:
Put all the files for each application in the same directory (and appropriate sub directories)
If you don't have ANY files that overlap, you can get away with this. Of course, it's likely that you won't with such files as the default or index pages, etc. And this would be pretty messy anyway.
Put all the non-binary files for each app in an appropriate subdirectory and the binaries in the main virtual's \bin directory.
You'll be able to do this only if each application's binary files don't overlap by name AND there are no namespace ambiguity conflicts between assemblies (two different assemblies by file name, but with the same namespace). The latter is much less likely to happen if you are trying to piggy-back two different applications.
The big problem I see with the latter solution is that any parts of the application that make use of application root references will break. When some code tries to resolve a reference to some resource (like an image) based on an application root reference such as
~/images/logo.gif
the ~ will get resolved to the virtual directory, but will not include the additional (non-virtual and non-app starting point) subdirectory in which the application lives. So instead of this:
/vd1/app1/images/logo.gif
you'll end up with this:
/vd1/images/logo.gif
Obviously, that won't work.
So... you won't break either app if you can put them both in the same virtual directory, however, you'll have to check for file conflicts and such. Possible namespace conflicts will be unavoidable without separate application starting points.
Can't you just put each app in a separate subdirectory in either of the virtual directories. e.g. if you had http://server.com/vd1, you could partition it like http://server.com/vd1/app1, http://server.com/vd1/app2, etc.

Resources