How to access properties from settings.xml to spring.xml and pom.xml to spring.xml - spring

I am new to maven spring.I have two questions.
How to access property set in settings.xml to spring.xml
How to accesss property set in pom.xml to spring.xml
Thank you.

You want to filter your resources, a maven term that means replacing property placehoders in one file with values from your maven pom. To do this you use the resources plugin in your build configuration.

Related

How to get data for a particular log4j2 property from an alternative source (application.properties)

Having a standard configuration for log4j2 and spring property-file on classpath application.property.
log4j2.xml
<Properties>
...
<Property name="APP_LOG_ROOT">${bundle:application:log.root.dir}</Property>
...
</Properties>
application.properties
...
log.root.dir=/opt/tomcat/logs
...
The data is read into the log4j2.xml correctly, but what if I want to get an alternative property when creating an artifact with maven and put diferent application.property:
mvn clean install -Dapplication.properties.path=file:/some_path/application.properties
?
After that, I can correctly read the new properties.
#Value("${log.root.dir}")
private String ololo;
but the log4j2 cannot do this on its own.
If you want to use any value from Spring's Environment in a Log4j2 configuration file, you need to use the Spring Boot Lookup.
After adding log4j-spring-boot to your classpath, you just need to replace
${bundle:application:log.root.dir}
with
${spring:log.root.dir}

How to set a spring datasource url to a resources folder?

I have a hsqldb file in my project resources folrder "src/main/resources/mydb.data"
In my application.properites I need to set the path with spring.datasource.url=
How I can achieve that?
spring.datasource.url=.... ?
One solution would be to use Maven resource filtering. Just use something like this in your application.properties:
spring.datasource.url=jdbc:hsqldb:file:#basedir#/src/main/resources/mydb.data
Instead of using basedir you can define something like darasource-url in your pom.xml and use this property in your application.properties:
pom.xml
<project>
<!-- ... -->
<properties>
<datasource-url>jdbc:hsqldb:file:${basedir}/src/main/resources/mydb.data</datasource-url>
</properties>
<!-- ... -->
</project>
application.properties:
spring.datasource.url=#datasource-url#
Notice: Using the spring-boot-starter-parent as parent, you have to use #..# instead of ${..}, see 2.1.1. Automatic Property Expansion Using Maven in the Spring Boot How-to-Guides.

maven: set property in/from plugin's pom.xml and access it in pom.xml which calls the plugin. how?

i'm trying to set a property from a plugin it's pom.xml and access that property from the plugin-caller-pom.xml which calls that plugin. but the tries with different plugin like antrun (script::javascript) or properties-maven-plugin or maven-surefire-plugin were all not successfull.
have some one tried that before and can tell me the way, how to do this?
Thank you very much.
Regards

Maven <LocalRepository> tag in pom.xml

By default Maven downloads all the dependencies to ${user.home}/.m2/repository/ dirctory.
I read about the tag LocalRepository which allows us to change the default path. I tried adding this tag add different locations in pom.xml file. But I could not find its exact location in the pom.xml file.
Do I need to put it in settings.xml or pom.xml?
can you please help me to add this tag to correct position in xml file.
<settings>
<localRepository>
D:\Ravindra\Projects\MavenSpringJar\
</localRepository>
</settings>
Is it inside <project>,<dependencies>,<dependency> tag?
Thanks.
The localRepository tag is only allowed within the setttings.xml file but not in the pom.xml file.

Changing the name of the generated war file from command line with maven

According to the maven war plugin documentation I should be able to set the name of the generated war file with the parameter warName. Is it not possible to do this from the command line with mvn -DwarName=mySpecificName package? When I run maven like this the war file still gets the default name.
My webapp project is part of a multi module project and I only want to change the final name of the war file, not any other projects generated artifact.
I am using maven 3.0.4 and version 2.3 of the war plugin.
You can achieve the same effect by maven property.
1) Define a property via
<properties>
<my.warName>xxx</my.warName>
</properties>
You can overwrite the default value by "-Dmy.warName=commandlineWarName"
2) Redefine the war name
<build>
<finalName>${my.warName}</finalName>
<!-- ... -->
</build>
After looking at the code of the war plugin I realize that it is not possible to set the warName parameter from command line. I assumed that all parameters were possible to set from the command line. This assumption was incorrect.

Resources