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 7986113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:45:26+00:00 2026-06-04T11:45:26+00:00

I have a Java EE 6 app that I build with Maven, code in

  • 0

I have a Java EE 6 app that I build with Maven, code in NetBeans 7 and deploy on GlassFish 3.1.2. As I near completion, I find myself deploying demo builds.

The problem is that I don’t have any dead easy way to build for different environment such as dev, QA, demo, prod, etc. For some stuff, I’ve been using a Java class with a bunch of static getters that return values based on the value of an environment constant. But this doesn’t help me with conditionally setting

  • javax.faces.PROJECT_STAGE (web.xml)
  • database credentials (glassfish-resources.xml)
  • mail servers (glassfish-resources.xml)
  • JPA logging level (persistence.xml)

and probably a number of other things I can’t think about now that are scattered across XML files.

Is there any way to define multiple versions of these configuration files and just set a flag at build time to select the environment, while defaulting to dev when no environment is specified? Is there a way I could make Maven work for me in this instance?

  • 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-04T11:45:27+00:00Added an answer on June 4, 2026 at 11:45 am

    You can use maven to achieve that. Especially using resource filtering.

    First, you can define list of profiles:

      <profiles>
        <profile>
          <id>dev</id>
          <properties>
            <env>development</env>
          </properties>
          <activation>
            <activeByDefault>true</activeByDefault> <!-- use dev profile by default -->
          </activation>
        </profile>
        <profile>
          <id>prod</id>
          <properties>
            <env>production</env>
          </properties>
        </profile>
      </profiles>
    

    Then the resources that you need to filter:

      <build>
        <outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
        <filters>
          <filter>src/main/filters/filter-${env}.properties</filter> <!-- ${env} default to "development" -->
        </filters>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <includes>
              <include>**/*.xml</include>
              <include>**/*.properties</include>
            </includes>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>
    

    And then your custom properties based on profiles in src/main/filters directory:

    filter-development.properties

    # profile for developer
    db.driver=org.hsqldb.jdbcDriver
    db.url=jdbc:hsqldb:mem:web
    

    and

    filter-production.properties

    # profile for production
    db.driver=com.mysql.jdbc.Driver
    db.url=jdbc:mysql://localhost:3306/web?createDatabaseIfNotExist=true
    

    to use production profile, you can package war using mvn clean package -Pprod command.

    Here you can see the sample project that use profile in maven.

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

Sidebar

Related Questions

I have a Flex/Java web application that uses Maven as a build tool. Currently,
I have a java app that uses log4j. Config: log4j.rootLogger=info, file log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=${user.home}/logs/app.log log4j.appender.file.layout=org.apache.log4j.PatternLayout
I have a Java app that can authenticate to LDAP by logging users into
I'm have a Java app that also runs as an applet. The app also
I have a large Java app that uses massive amounts of memory at times
I have a Java EE App that has JSF2 + PrettyFaces + Facelets +
I have a legacy Java (not my native language) app that I'm trying to
I have around 4000 entities that I need to insert into a Java App
I am using maven to build my java app, Jenkins for CI and Sonar
I'm trying to build my Flex/Java web app from within IntelliJ rather than have

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.