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

  • Home
  • SEARCH
  • 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 5936937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:28:07+00:00 2026-05-22T15:28:07+00:00

What the easiest/right way to conditionally exclude a java file from compilation in a

  • 0

What the easiest/right way to conditionally exclude a java file from compilation in a maven project?

I would like to be able to set a ‘boolean’ properties in the pom.xml:

<properties>
    <IncludeMayBe>true</IncludeMayBe>
</properties>

...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <excludes>
            ????

        </excludes>
    </configuration>
</plugin>

Is there a way to fiddle something with the compiler plugin? Or should I go for profiles? I feel like creating a profile is overkill, but may be this is the only solution…

EDIT:

We have established that profiles are the solution. For conditional activation from within the pom.xml, one can use the following:

<profiles>
  <profile>
    <activation>
      <property>
        <IncludeMayBe>true</IncludeMayBe>
      </property>
    </activation>
    ...
  </profile>
</profiles>
  • 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-05-22T15:28:07+00:00Added an answer on May 22, 2026 at 3:28 pm

    I suggest you use the Build helper maven plugin.
    Using this, you can have several source directories.
    Then you can control what source directories are included using profiles.

    Assuming you have your monitoring classes under src/monitoring/java you could add the following to the element in your pom.xml

    <profiles>
        <profile>
            <id>monitoring</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>add-sources</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>${basedir}/src/monitoring/java</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the easiest way to separate the directory name from the file
What's the easiest/best way to generate Java from an XSD using MOXy under Maven-3?
What would be the easiest way to be able to send and receive raw
I would like to know the easiest way to check it the user typing
What's the easiest/best way to register your program in explorers right-click menu using .NET
What's the easiest way to convert a percentage to a color ranging from Green
What would be the easiest way to detach a specific JPA Entity Bean that
I'm currently internationalizing an existing PHP project and thought the easiest way to do
I was wondering the easiest way (open source control / .NET control) to set
I would like to move a DOM element once the right arrow key is

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.