Setting System Properties for the maven-surefire-plugin via CLI - maven

I am currently working on a use-case where I have to set a system property for the maven-surefire-plugin via command line. I've tried to use the systemPropertiesFile property but it seems like my build doesn't pick up the properties in the file . Here's the syntax that I've tried:
mvn install -DsystemPropertiesFile=<path-to-file>
I'm using Maven 3.0.5 for this. Setting the same property via the POM file works fine, but unfortunately that is not a solution I can use. Am I missing something?

systemPropertiesFile is not exposed as a user property, so if you don't want to change pom.xml you could use argLine:
mvn install -DargLine="-DmyProperty=abc -DotherPoperty=def"

Related

How to specify additional classpath in command line when running Spring Boot application via Maven?

I'm running an application (in GitBash on Windows) with:
mvn spring-boot:run
Except that the application is looking for a properties file, which I'd like to make available in the classpath. But I don't want to have to change any code in this application.
Is there a way to specify additional classpaths when running this command? I've tried various forms of:
mvn spring-boot:run -Dclasspath="C:\\path\\to\\config\\dir"
or
mvn spring-boot:run -Dclasspath=/C/path/to/config/dir
And I've tried setting $CLASSPATH.
None of this works, but I don't get a clear idea about where it is breaking because the only error is that my properties file cannot be found.

How do I set up Spring and Maven environment for working offline?

I need to set up Spring and Maven for working offline. I am working with Spring Tool Suite.What environment variables do I need to configure besides M2 env var? When I try to add dependencies in pom.xml, and type springframework, nothing comes up in the search bar. I get "Core exception Could not calculate build plan Plugin org.apache.maven.plugins:m. I understand STS uses web services to locate the jars, so how do I configure Spring and Maven to work offline? Thank you.
Maven uses central repositoty to update dependencies via internet if you want run it offline you need to configure you local repository.See Setting local Maven repository
This is something that you will find very difficult or near impossible unless you somehow get all the relevant jars from spring and place them in your .m2 repo directory.
Your question has been asked a number of times on here ...
Have a look through these 2 questions which I assume is exactly what you have encountered.
Question 1
Question 2
Also one last note ...
After you setup your variables did you restart your PC I know sometimes I forget to do this when updating environment variables.
Before you go offline run the following:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
mvn install -o
It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:
true

Maven: Set the settings.xml location in the pom.xml?

Is it possible to set the location of the settings.xml file inside the pom.xml file.
I know you can do it from the command line typing mvn -s location/of/settings.xml, but I wanted to know if I can set that within the pom.xml so I don't have to keep typing through command line.
No. And that's probably a horrible idea, from a security standpoint. It'd allow the creator of a pom to bypass all your settings.xml settings. If you do the mvn -s location/of/settings.xml you will at least know it happened. But if you just randomly build a project, who knows how malicious that project's creator was.
No, but you can set what you need from the settings.xml file into the pom.xml and it will override what's in settings.xml
Something that may help you get what you want are profiles:
A profile in Maven is an alternative set of configuration values which set or
override default values. Using a profile, you can customize a build for
different environments. Profiles are configured in the pom.xml and are given an
identifier. Then you can run Maven with a command-line flag that tells Maven to
execute goals in a specific profile. The following pom.xml uses a production
profile to override the default settings of the Compiler plugin.
Source: http://maven.apache.org/pom.html#Profiles

Changing java service wrapper conf file property inside a pom

I'm using java service wrapper in a project and want to change wrapper.logfile.maxsize
property of the wrapper.conf file.The thing is that it would be better if I can change it inside maven pom.xml file. So can anyone please tell me whether this is possible and if so how to do it ?
Thanx...
Use Maven Resource Plugin's Filtering feature. Let's say the line that needs to be configured by Maven looks like
wrapper.logfile.maxsize=500
Replace it with:
wrapper.logfile.maxsize=${wrapper.logfile.maxsize}
add filtering in the project/build/resources/resource/ section with:
<filtering>true</filtering>
and populate the right value from command line:
mvn resources:resources -Dwrapper.logfile.maxsize="500"

How maven pom.xml file convert configurations into system properties?

As we all know, suppose we define 'transportation' in pom.xml in maven,
after we run command like 'mvn jetty:run' the property 'db.name' can be discovered by other configuration, like 'hibernate.cfg.xml'. That's fine.
But now, I configure this project to run on tomcat directly , by 'run on server' from eclipse, instead of by maven command. (I did this by configure a project facets in eclipse, make it can use 'run on server' menu). You can see now I just run with eclipse, nothing to do with 'maven' or 'pom.xml', but it still use properties like 'db.name'. If I need change to another db, I had to change the 'db.name' property, then run some command in maven to make it take effect.
Can any body give some explanation about how it works? Does maven command generate some file at some place that takes the properties?
Properties are set for virtual machine. Maven run new/existing (dependent on configuration) instance of runtime environment. So you can pass properties as
-Dkey=value (or <key>value</key> in pom)
Check in eclipse configuration if you can pass arguments when you run tomcat?
Eclipse maven plugin (from Eclipse foundation) understands the pom.xml and usually syncs with any changes.
But sometimes I observed that it goes out of sync, and to fix that problem I need to delete the temporary folders/files created by Eclipse (.settings, .classpath and .project) and import again.

Resources