Search code examples
javaapacheprojectpackagedirectory-structure

Separate code to main and test branches under `src` folder without changing packages names


I would like to adopt an Apache Software Foundation's standard directory structure to already existing project, which is:

module/
  src/
    main/
      java/
        com.mycompany...
    test/
      java/
        com.mycompany...

The issue is that after moving the sources from src/com.mycompanyto src/main/java/com.mycompany and src/test/java/com.mycompany the IDE (Eclipse) returns a warning and proposes to rename the packages from com.mycompany to main.java.com.mycompany and test.java.com.mycompany respectively.

Important note:
Since this is a legacy project without any Maven integration, but which is still in use in production, I would like to reduce a changes to the project as much as possible but still separate the code on production and unit test code.

Is there any way to avoid packages renaming in all source-files but still to use Apache's source directory structure?


Solution

  • You can do it in the pom.xml but you can also edit the project in Eclipse and define the source folders there

    I noticed you actually misread the Apache standard structure, it follows the Maven convention src/main/java etc so I would use that. Then, if you use some form of Maven-Eclipse integration the source folders should automatically be set correctly by default. I used to do that with mvn eclipse:eclipse (using the eclipse-maven-plugin) but that's a long time ago - I use Intellij now. I'm guessing by now Eclipse picks up the source path from Maven automatically.