where does jetty serve files from - jetty-9

I just installed jetty 9.4.6. I dropped one of the war files from the demo area into $JETTY_BASE/webapps. The war file got expanded into /tmp/jetty-10.1.100.103-8080-test.war-_test-any-4774924669679182185.dir
I then tried a curl on it like this: :8080/test/index.html. I get a 503 error. I verified that index.html exists.
So does jetty serve the compressed war file or does it serve from the tmp folder? Any doc links would be greatly appreciated.

Yes, it creates a temp directory, though you can also define and persist your own if you'd like.
By default, Jetty will create this directory inside the directory
named by the java.io.tmpdir System property. You can instruct Jetty to
use a different parent directory by setting the context attribute
org.eclipse.jetty.webapp.basetempdir to the name of the desired parent
directory. The directory named by this attribute must exist and be
writeable.
You can find more in the official documentation here.

Related

Download files to Openshift directory

I am using Openshift to allocate a Java application. This app contains a method that needs to download a xml file inside the project to explore it later.
So, the thing is that I need the path for the directory where I want to download the file.
And that is the trouble, I don't know how to call the path I want.
For example:
String filePath = "webapps/downloads/file.xml";
But Openshift tells me the error:
/var/lib/openshift/56e18fa***********0029/jbossews/webapps/downloads/file.xml
(No such file or directory)
The structure of my project is:
Project
src > main
java
resources
webapp
webapps > downloads
I Hope I have explained well. Thanks in advance!

How to externalize i18n properties files in spring-boot applications

I’ve succeed to externalize my spring-boot configuration file (application.properties) in a config folder when I run my spring-boot application as a unix service with the help of the official spring documentation https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
I have also some i18n messages.properties files in my src/main/resources that I would like to externalize in the same config folder but I failed to do it. I’ve tried a lot of things, like playing with spring.messages.basename but unfortunately, it doesn’t work.
I’m using the latest version of spring-boot, and use auto configure mode with the default i18n properties name messages.
What am I missing??? thanks for your help.
Just a few notes:
classpath:message - will always lookup embeded message_xxx files
classpath:/message and classpath:message are equivalent
file:message - will lookup jar's external current directory e.g. ./message_en.properties <- this is what you want
file:/message - you have to put your message files to root "/" to make it work
use notation file:config/message if you need to put in config folder together with your
./config/application.properties
I think you need a leading slash.
Try: spring.messages.basename=classpath:/config/messages
I think, resource bundle is default to classpath. So there's no need to append it. just go straight to your folder location from classpath.
Try this: **assuming your config is inside static folder
spring.messages.basename=static/config/messages

serving files from a spring boot war file

I've followed the guide here for turning a "hello, world" level Spring Boot app to a war file. I can run this war like a jar and it will return the simple template.
What I don't understand is why I can't access a main.css file I've created. I've placed it in the resources directory under "static/css/main.css" and according to the docs here Spring Boot will automatically server files under "resources", "static", "public", and "META-INF/resources". However, when I build my war file and run it I can't query those files in the browser (like http://localhost:8080/static/css/main.css). Have a missed a step? If I peek into the created war file I see the "static" directory in "WEBINF/classes" right beside the "templates" directory and the directory holding my application.
Files in src/main/resources/static are served from / so you don't need static in the path. You CSS file should be available from http://localhost:8080/css/main.css

How to configure relative datasource file for SQLite?

I'm trying to configure a SQLite database for an Spring Web App. The thing is that I'm not able to reach the database file that I've created in src/main/resources using a relative path.
I've tried several configurations for the jdbc url but none of them worked:
jdbc:sqlite:mydb.sqlite (here I changed the file location to the project root)
jdbc:sqlite:${jdbc.url} (here I passed the url as a parameter thru PropertyPlaceholderConfigurer)
jdbc:sqlite:src/main/resources/mydb.sqlite
A weird thing that I realized about is that the app is using Eclipse's directory as the directory to find the database file. I mean, when I put jdbc:sqlite:mydb.sqlite it creates an mydb.sqlite on Eclipse's directory not in project's root.
Check the JVM system property named "user.dir" and set the path relative to it. It is the "current dir" of your java app. It can be different if you run from eclipse or from cmd line or inside webserver(tomcat).
So, System.getPropery("user.dir") will tell you current dir of your running app. Set the path to db relative to that directory.
I would say eclipse does not run your app from the project dir, as it should by default. Check your "run" settings in the eclipse.

How to make GPE see my war directory?

I already have a war directory created through maven and i would like to use that directory instead of src/main/webapp but the target directory is not seen by GPE . Other than project refresh i do not know what wlse to try.
Change Default Output Folder path from Java Build Path-> Source

Resources