从OS系列中选择maven配置文件

时间:2016-07-19 18:13:29

标签: maven operating-system pom.xml maven-profiles

我想根据操作系统类型设置一些属性,所以我在package merge.tables; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class PostgreTableMerger { private static String dbOrigin = "jdbc:postgresql://server1:5432/DB"; private static String dbDest = "jdbc:postgresql://server2:5432/DB"; private static String tableToMerge = "important_results"; public static void main(String[] args) throws Exception { Connection dbConnOrigin = DriverManager.getConnection(dbOrigin, "pgadmin", "pgadmin"); Statement dbOriginStat = dbConnOrigin.createStatement(); Connection dbConnDest = DriverManager.getConnection(dbDest, "pgadmin", "pgadmin"); Statement dbDestStat = dbConnDest.createStatement(); String sqlToExecute = "SELECT * FROM " + tableToMerge; ResultSet assets = dbOriginStat.executeQuery(sqlToExecute); ResultSetMetaData rsMeta = assets.getMetaData(); while(assets.next()){ String insertSQL = "INSERT INTO " + tableToMerge + " VALUES("; for(int i = 1; i <= rsMeta.getColumnCount(); i++){ String value = assets.getString(i); if(assets.wasNull()){ insertSQL += "NULL,"; }else{ insertSQL += "'" + value + "',"; } } insertSQL =insertSQL.substring(0, insertSQL.length()-1) + ")"; try{ dbDestStat.executeUpdate(insertSQL); }catch(SQLException e){ //TODO: attempt to update the row in the event of duplicate key } } return; } } 中有以下内容:

pom.xml

在我的Mac上,我会检查哪些配置文件处于活动状态:

<project ...>
    <profiles>
        <profile>
            <id>KenMacbook</id>
            <activation>
                <os><family>mac</family></os>
            </activation>
            <properties>
                <test.r.version>3.3</test.r.version>
            </properties>
        </profile>
        <profile>
            <id>LinuxBox</id>
            <activation>
                <os><family>unix</family></os>
            </activation>
            <properties>
                <test.r.version>3.2</test.r.version>
            </properties>
        </profile>
    </profiles>
    ...
</project>

因此,% mvn help:active-profiles | grep -v INFO Active Profiles for Project 'com.foo:bar:jar:2.0.3-SNAPSHOT': The following profiles are active: - nexus (source: external) - KenMacbook (source: com.foo:bar:2.0.3-SNAPSHOT) - LinuxBox (source: com.foo:bar:2.0.3-SNAPSHOT) 个人资料的<activation>似乎未成功排除Mac上的个人资料。我是否误解了配置文件选择的工作原理?

Maven详情:

LinuxBox

1 个答案:

答案 0 :(得分:3)

正确的解决方案是指定名称。

<activation> 
            <os> 
                <family>unix</family> 
                <name>Linux</name>
            </os> 
</activation>  

完整的跨平台解决方案是:

<profile>
  <id>mac</id>
  <activation>
    <os> 
      <family>mac</family>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.cocoa</module>
      </modules>
</profile>
<profile>
  <id>unix</id>
  <activation>
    <os>
      <family>unix</family>
      <name>Linux</name>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.gtk</module>
      </modules>
</profile>
<profile>
  <id>windows</id>
  <activation>
    <os>
      <family>windows</family>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.win32</module>
      </modules>
</profile>

来源:http://maven.40175.n5.nabble.com/Profile-activation-for-mac-and-linux-td3263043.html