简体   繁体   中英

JAVA SPRING - Using Maven, steps to create 2 war file (quality & production)

Can anyone please help me to create 2 war files using maven, java spring?

Requirement: Need 4 war file
For that 1st create 2 war file
(make another 2 copy from this with different name for oauth)
database name only diff between staging & production war

staging ( http://10.19:3006/imdesk_imapi_staging)-sql datasource- for staging
1)war - api
2)oauth staging war - copy

production ( http://10.19:3006/imdesk_imapi_production)-sql datasource for ****production****
1)api - war
2)oauth war - copy

work with maven profiles http://maven.apache.org/guides/introduction/introduction-to-profiles.html

so you can create different artifacts for different stages

I see two paths you could take to solve the issue:

1. Use maven profiles.

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

How can a profile be triggered? How does this vary according to the type of profile being used? A profile can be triggered/activated in several ways:

  • Explicitly
  • Through Maven settings
  • Based on environment variables
  • OS settings
  • Present or missing files
  • Details on profile activation

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.

mvn groupId:artifactId:goal -P profile-1,profile-2

2. Use Spring profiles.

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments. Any @Component or @Configuration can be marked with @Profile to limit when it is loaded:

`@Configuration
 @Profile("production")
   public class ProductionConfiguration {
        // ...
   }

In the normal Spring way, you can use a spring.profiles.active Environment property to specify which profiles are active. You can specify the property in any of the usual ways, for example you could include it in your application.properties:

spring.profiles.active=dev,hsqldb or specify on the command line using the switch --spring.profiles.active=dev,hsqldb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM