Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:37:50+00:00 2026-06-15T19:37:50+00:00

Ok I am switching from ant to maven on an android project and wondering

  • 0

Ok I am switching from ant to maven on an android project and wondering if it the following would be easy to implement:

Currently I have a custom build.xml script which has several targets for creating release builds. Each of them is used to build the application to run against a different server URL, where the server can be a dev, production, staging, or even deployment servers we have in other countries.

The reason is that our application will run against several different servers depending who gets it, and I don’t want that to be something the user chooses. Instead it should be hardcoded into the application, which is how it works currently.

This is fairly easy to setup in ant, I just take the values from the [env].properties file, and then replace out server_url string in res/values/config.xml. For instance:

ant release-prod

Would pull read a file named prod.properties which defines what the server_url was. I store the config.xml file in config/config.xml as so:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="config_server_url">@CONFIG.SERVER_URL@</string>
</resources>

Then my ant script does this:

<copy file="config/config.xml" todir="res/values" overwrite="true" encoding="utf-8">
    <filterset>
           <filter token="CONFIG.SERVER_URL" value="${config.server_url}" />
    </filterset>
</copy>

Where config.server_url was defined in prod.properties.

I’m wondering how I could accomplish something similar with Maven? Any ideas. I looked up how to read property files with maven and it looked like the results were mixed whether that would work or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:37:51+00:00Added an answer on June 15, 2026 at 7:37 pm

    In Maven, this is called resource filtering, android-maven-plugin support filtering the following resource types:

    • AndroidManifest.xml, see this answer.
    • assets/, see this answer.
    • res/, see below.

    Sample res/value/config.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
      <string name="config_server_url">${config.server.url}</string>
    </resources>
    

    Sample pom configuration for filtering all xml file under res/ directory:

    <build>
      <resources>
        <resource>
          <directory>${project.basedir}/res</directory>
          <filtering>true</filtering>
          <targetPath>${project.build.directory}/filtered-res</targetPath>
          <includes>
            <include>**/*.xml</include>
          </includes>
        </resource>
      </resources>
      <plugins>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <executions>
            <execution>
              <phase>initialize</phase>
              <goals>
                <goal>resources</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>com.jayway.maven.plugins.android.generation2</groupId>
          <artifactId>android-maven-plugin</artifactId>
          <extensions>true</extensions>
          <configuration>
            <sdk>
              <platform>10</platform>
            </sdk>
            <undeployBeforeDeploy>true</undeployBeforeDeploy>
            <resourceDirectory>${project.build.directory}/filtered-res</resourceDirectory>
          </configuration>
        </plugin>
      </plugins>
    </build>
    

    There are several ways to define the substituted value, you can define them in an external properties file with properties-maven-plugin. For simplicity, I prefer to use Maven profiles and define them in pom.xml, like so:

    <profiles>
      <profile>
        <id>dev</id>
        <properties>
          <config.server.url>dev.company.com</config.server.url>
        </properties>
      </profile>
      <profile>
        <id>Test</id>
        <properties>
          <config.server.url>test.company.com</config.server.url>
        </properties>
      </profile>
      <profile>
        <id>Prod</id>
        <properties>
          <config.server.url>prod.company.com</config.server.url>
        </properties>
      </profile>
    </profiles>
    

    Then use mvn clean install -Pxxx to build corresponding apk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am switching a project from Ant to Maven. I have my unit tests
I am currently switching from ant to gradle for my multi module web application
I'm looking at switching my projects build from Ant to leiningen and wanted to
I am currently in the process of switching from Android to the iPhone SDK.
After switching from maven 2 to maven 3 I have found out having 0%
I'm switching from ActiveRecord to Dapper. I have a simple Project class with a
I am considering switching a Maven project that I manage to Apache-Ant/Ivy. I need
I am currently switching from AS3 to JavaScript. I still have some trouble with
I'm switching from MySQL to PostgreSQL and I was wondering how can I have
I'm just switching from Emacs to IDEA and it would be a great help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.