Java Academy

Master Java Development

Menu

Core Java

Servlets

JDBC

Microservices

Build Tools

APIs

Build Tools · Lesson 10

Build Profiles and Environments

Adapting a Build to an Environment

A build profile selects configuration for a context such as development, testing, or production. Profiles can change endpoints, logging, feature flags, and packaging details, but secrets should come from secure runtime configuration. The goal is one repeatable build process with explicit differences.

Reading an Environment Property

Java code can read a property supplied by the build or deployment environment. Keep defaults safe for local work and validate required production values at startup.

public class EnvironmentSettings {
    public static void main(String[] arguments) {
        String environmentName = System.getProperty("app.environment", "development");
        boolean verboseLogging = Boolean.parseBoolean(
                System.getProperty("app.verboseLogging", "true"));
        System.out.println(environmentName + "; verbose logging: " + verboseLogging);
    }
}

Profile Comparison

EnvironmentTypical settingsMain goal
DevelopmentLocal database, verbose logsFast feedback
TestIsolated services, test dataRepeatable verification
StagingProduction-like infrastructureRelease confidence
ProductionSecure endpoints, limited logsReliability and safety

Common Mistake and Practices

Common Mistake: Committing credentials into a profile file because it is convenient. Repository history and build logs can expose secrets long after the file is deleted.

  • Keep secrets outside source control.
  • Name profiles explicitly in CI.
  • Validate required properties early.
  • Keep profile differences minimal.
  • Test the production profile before release.

Real-World Use Case

The academy uses a test profile with an isolated database and a production deployment that supplies credentials through a secret manager. The application code stays unchanged between environments.

Quiz Check

Quick Knowledge Test

Loading quiz questions...