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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:27:30+00:00 2026-05-13T05:27:30+00:00

We are using Maven to compile our project on a build server. We update

  • 0

We are using Maven to compile our project on a build server. We update our sources from SVN and then run “mvn install” from the project folder, building a jar we then deploy to our production servers.

To save time on compilation, we keep the compiled classes before we recompile (in the target/classes folder maven creates). This way, Maven only needs to recompile new or changes java files.

But there is a problem with moved/deleted files: the SVN update removes the .java files from the sources path, but Maven doesn’t remove the compiled .class files from target/classes. Same goes for files which are deleted from the main/recourses folder. So, the deleted/moved classes and deleted resources still end up in the jar file we deploy to our production servers, and this causes problems.

I know we can “mvn clean” to get rid of any compiled files, but this way we need to recompile the whole project on every build, which costs a lot of time.

Does anyone know a way to remove obsolete .class files and resources before or during Maven compilation?

  • 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-13T05:27:31+00:00Added an answer on May 13, 2026 at 5:27 am

    So, the deleted/moved classes and deleted resources still end up in the jar file we deploy to our production servers, and this causes problems.

    You really should perform a full clean build when building artifacts that are going to be deployed to your production servers. It’s not only a best practice for reproducible builds (as mentioned in Hudson Best Practices for example), but, more important, it’s the only way to prevent runtime errors with multi modules builds (unless you use the maven-incremental-build plugin). Imagine the following situation:

    module-parent
    |--- module-api
    `--- module-impl
    

    The API module defines interfaces that are implemented by the IMPL module (which thus depends on the API module). If you change the API module by modifying a method signature and doesn’t change anything in the IMPL module, performing a build from the parent module will succeed, the IMPL won’t be recompiled and the whole thing will break at runtime (see this discussion about this behaviour). What you are currently doing is really not safe!

    Does anyone know a way to remove obsolete .class files and resources before or during Maven compilation?

    I’m not aware of anything doing that. And as I said, your current practice is not safe. You should change it, at least at the continuous integration server level and especially for “production builds”.

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

Sidebar

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.