How to configure relative datasource file for SQLite? - spring

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.

Related

What creates target directory in spring boot application?

I am trying to set up debugging by this article:
https://www.jetbrains.com/help/idea/run-and-debug-a-spring-boot-application-using-docker-compose.html#35ea56fc
it works for me on the application from the article but does not work on real application.
I have noticed the difference is - in real application there is no target directory.
But in the article there is a line:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -Djava.security.egd=file:/dev/./urandom -jar /project/target/demo-0.0.1-SNAPSHOT.jar
so I assume it expects target directory. I do not see the demo-0.0.1-SNAPSHOT.jar file in the demo application. Is it created temporarily and deleted?
I see there is no target directory in the repository so something creates it - what? https://github.com/IdeaUJetBrains/SpringBootDockerDemoDebug
And probably this might be one of reasons why code does not stop at breakpoints?
And also how it works at all? Why there is project directory before target directory but project directory is not created and it still works in demo application?

Spring boot external properties not working

My project structure looks like as attached file. Even though I have profile specific properties, I would like to run my app with external properties file i.e., outside of jar file.
I tried with following command:
java -jar test_service.jar --spring.config.location=file:///C:/external_props/test.properties
But its taking application-default.properties file.
from log file:
No active profile set, falling back to default profiles: default
Why it is not taking external properties file ?
When you pass --spring.config.location command line argument SpringBoot won't consider application-*.properties files in src/main/resources directory. The filename you mentioned for --spring.config.location is taken as base filename, in your case test. So, it will only load test.properties file from that path you provided as default profile.
If you want to enable certain profile, say prod, you need to create file C:/external_props/application-prod.properties and enable prod profile using --spring.profiles.active=prod.
Spring will automatically look for some property file in a specific location.
From where you execute the jar file, Spring will look in that directory for a property file called application.properties
An other way is to put a config directory in the directory you execute the jar from and put the application properties in there.
There is one more option and that is the -Dspring.profiles.active={profiles} parameter.
Spring will then look in the directory or config directory to application-{profile}.properties
Reference:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
Also i think you use the
--spring.config.location=file:///C:/external_props/test.properties
is not used correctly for a windows based file path.
Windows uses the \ instead of the /.

where does jetty serve files from

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.

ibm-application-bnd.xml overwritten

I work on an existing Maven project with Eclipse Luna and WebSphere 8.5.5.1.
The source of the ibm-application-bnd.xml is:
D:\projects\svn\application\ear\src\main\application\META-INF\ibm-application-bnd.xml
Once a day, at a random moment, the application folder itself is overwritten with the ear-file, so the \main folder contains a binary file named application and is actually the ear file because I openend the file because I saw it had the same size as the ear (8 MB).:
D:\projects\svn\application\ear\src\main\application
The happens at least once a day, and I have the impression that Eclipse, or JRebel of WebSphere creates this file.
The result is that I have to quit Eclipse, delete the file and update from SVN to get the application folder with the binding xml back.
Any thought how to fix this?
Easy way you could stop the folder from being deleted (and perhaps also find the culprit) is to open command prompt in that directory - it won't allow the folder to be removed in that case.

How to package JMeter with Jar Bundler on Mac

I'm unable to use "Jar Bundler" on mac to create JMeter.app from ApacheJMeter.jar, I was wondering if anyone else had previous experience with configuring this tool? The problem for me seems to be that the lib folder being searched is set to an incorrect base path:
org.apache.jmeter.NewDriver: JMeter home directory was detected as: /Users/username/Applications/JMeter.app/Contents/Resources
I looked here: http://developer.apple.com/library/mac/#documentation/Java/Reference/Java_InfoplistRef/Articles/JavaDictionaryInfo.plistKeys.html
But no matter how I configured any of the said properties, the logs looked the same.
The real trick is making sure the bin and lib folders can be found. The only jar file you will need to add is ApacheJMeter.jar. Look in the bin/jmeter script for additional properties to put into the properties tab of the Jar Bundler. The java arguments in the bin/jmeter script should be copied into the VM Options field. Check Set Working Directory to Inside Application Package. Now create application. Open up the .app folder that was just created and copy the bin and lib folders into the Resources directory. Done.

Resources