deploy and running with different configurations in maven - debugging

i search a method for Maven that accept different configurations for deploy and debug. I want to choose different web.xml-file. How to get it?
Greetz,
sheepy

You can use resource filtering to substitute values in the web.xml from properties declared in different profiles or in the command line option or you can use property to specify different web.xml in maven-war-plugin configuration.

Related

How to detect unexpanded or missing value properties in Maven?

I'm configuring a web app to use Maven filtering to expand property placeholders in configuration files for different environments.
Is there a way to detect if any property hasn't been expanded in the filter files, i.e. if I could end up with myprop=${customvalue} at some stage before deployment?

SpringBoot: GroupId and ArtifactId based on a property dynamically

Define GroupId and ArtifactId based on a property file
I would like to know if from Eclipse is possible to set dynamically the GroupId and ArtifactId from a property set on the file application.properties in a SpringBoot application
because from the same project I generate 2 different projects (core project and web project) based on #Profile
Attached Image
No it's not possible to set groupid and artifact id using properties file.But for profile setting using pom directly you can use below option.
"Profiles can be explicitly specified using the -P CLI option.This option takes an argument that is a comma-delimited list of profile-ids to use. When this option is specified, the profile(s) specified in the option argument will be activated in addition to any profiles which are activated by their activation configuration or the section in settings.xml"
Profiles can be activated in the Maven settings, via the section. This section takes a list of elements, each containing a <profile-id> inside.
<settings>
...
<activeProfiles>
<activeProfile>profile-1</activeProfile>
</activeProfiles>
...
</settings>
In case of using spring boot you can also apply spring.profiles.active=profile-1,profile-2
CHECKOUT THIS URL FOR FURTHER MORE
You want to built two or more different jars depending on the active profile set in project.
Maven can support this see https://maven.apache.org/guides/mini/guide-building-for-different-environments.html ,which creates profiles for building and packaging artifacts for different environments.
This feature was meant to support different build environments e.g production,development,testing... but i don't think anyone will be arresting you if you use profiles to modularize your project.

Simplifying deployment configs for SpringMVC project

We've multi module SpringMVC project, each having separate applicationContext.xml, currently we have to edit the applicationContext.xml files for every module before we deploy. It's painful and error prone. Is there a way to have only one property file that all other will contexts look at. Then we only have to edit one property file before we build and deploy. Thanks in advance.
It sounds like you should be using Spring's Profile support, which allows you to specify separate properties files per environment. You can pass the application an environment property spring.profiles.active and set it to say, "dev", "test", or "prod".
If you're using Spring Boot it can then automatically pick up distinct configuration per environment, application.dev.properties or application.prod.properties which will overwrite the standard application.properties with environment specific configuration.
If not using Spring Boot you would just have configure your Properties Sources per profile.
This is most definitely the preferred approach to changing configuration files at build or deploy time.
Reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-environment

Maven: is it possible to use a conditional properties filtering?

As we know there is a very useful option in Maven Resource plugin: we can use filtering to replace the placeholders in some resources files with some predefined values. The explanation can be found here: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
A question is: is it possible to use a conditional filtering? I.e. I want to replace some placeholders in my files but I want to do it basing on some conditions, for example:
if the value of myProperty = "DevelopmentSetup" then the replacement
comes from development.properties, otherwise use "ProductionSetup".
Can I do it with Maven?
While you cannot configure Maven's resource plugin to use conditional filtering (at least as far as I know), it is still possible with Maven to select a build profile based on the value of a particular property. As described on Maven - Introduction to build profiles, you can activate a particular profile when some property has a given value (scroll down to 'The profile below will activate the profile when the system property "debug" is specified with any value').
So, the solution to your problem would be to set up two profiles, development and production. In these profiles, you configure your resource filter settings accordingly to either use your development property file or production property file.
There is also some useful information in Maven: The Complete Reference. Especially the tips and tricks section.

Maven Variables are not replaced into installed pom file

We are using Maven(3.0.3) as build tool and we need to have different version for different environments (DEV , TEST, QA ) . If we pass version property value during build time based on environment , the installed POM doesn't have the passed property values instead it still has the ${app-version} string.
I saw already there is a bug for this http://jira.codehaus.org/browse/MNG-2971
Is there any other alternative ,because we cannot different POM file for different environments ,which will be hard to maintain..
Thanks
Vijay
Create different artifacts for the environments and use the parameter as a classifier. The pom is the same for all three artifacts but the classifier separates them.
Apparently Maven does not make any variable/property substitution when installing the POM. It is installed as is, that is the principle. You'd better not read any properties from POM (unless this is e.g. version number), bout you should configure your properties in external file (one per stage, e.g. dev.properties, test.properties, ...) and then configure Maven profiles (again, one per stage) and invoke Maven like mvn -Pdev depending on what you want to build. In profile you can package your final application with whatever properties you like (e.g. with the help of build-helper-maven-plugin:add-resource or maven-antrun-plugin + copy rule).
Alternatively you can filter your resources. For example, you can filter your Spring context XML file, which refers the properties file (so you package all property files, but Spring will refer only some specific). Or you can filter another properties file from which you will learn what is the "main" properties file to use (double indirection).
You should create the archives for your different targets within a single build and use as already mentioned the classifier to separate those artifacts from each others.

Resources