Maven Using filter~ It is Awesome

When you use maven Filter is very good for user
We can easily control enviroment of the project

Let's use Porifle

Ex> pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.mkyong.common</groupId>
 <artifactId>SpringMVC</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>SpringMVC Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.11</version>
   <scope>test</scope>
  </dependency>
  <!-- Spring framework -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring</artifactId>
   <version>2.5.6</version>
  </dependency>
  <!-- Spring MVC framework -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>2.5.6</version>
  </dependency>
  <!-- JSTL -->
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
   <version>1.1.2</version>
  </dependency>
  <dependency>
   <groupId>taglibs</groupId>
   <artifactId>standard</artifactId>
   <version>1.1.2</version>
  </dependency>
 </dependencies>
 <profiles>
  <profile>
   <id>dev</id>
   <activation>
    <activeByDefault>true</activeByDefault>
    <property>
     <name>env</name>
     <value>dev</value>
    </property>
   </activation>
   <properties>
    <appserver.home>dev</appserver.home>
   </properties>
  </profile>
  <profile>
   <id>real</id>
   <activation>
    <property>
     <name>env</name>
     <value>real</value>
    </property>
   </activation>
   <properties>
    <appserver.home>real</appserver.home>
   </properties>
  </profile>
 </profiles>
 <build>
  <filters>
   <filter>src/main/filter/${appserver.home}/spring-views.properties</filter>
  </filters>

  <resources>
   <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
   </resource>
  </resources>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
     <source>1.6</source>
     <target>1.6</target>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

project tree
src/main/filter/dev-spring-views.properties
                       /real-spring-views.properties
src/main/java
src/resources/spring-views.properties


command line
$ mvn clean package -P real


filters poperties will be injected into resources/spring-veiw.properties

if you want have sample

reply

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm