It depends on what that line is.
- If it's a source folder, use the
buildhelper-maven-plugin to
add a source folder in a
lifecycle phase before
generate-sources
, this will
automatically be picked up by the
eclipse plugin.
- If it's a classpath container, you
can use the classpathContainers
parameter
If you want to change the output folders (from target/classes
and target/test-classes
to something else), change them in the maven build configuration:
<build>
<!-- replace "target" -->
<directory>somedir</directory>
<!-- replace "target/classes" -->
<outputDirectory>anotherdir</outputDirectory>
<!-- replace "target/test-classes" -->
<testOutputDirectory>yetanotherdir</testOutputDirectory>
</build>
You can configure each of those three independently, and the changes will be picked up by the eclipse plugin, but it's considered good practice to put outputDirectory
and testOutputDirectory
inside directory
(usually by referencing ${project.build.directory}
), otherwise you break standard functionality like mvn clean
(it cleans ${project.build.directory}
):
<build>
<directory>bin</directory>
<outputDirectory>${project.build.directory}/main-classes
</outputDirectory>
<!-- this config will replace "target" with "bin",
compile src/main/java to "bin/main-classes"
and compile src/test/java to "bin/test-classes"
(because the default config for <testOutputDirectory> is
${project.build.directory}/test-classes )
-->
</build>
Reference:
Update: in your case I guess the only possible solution is to programmatically edit the .classpath
file. What I would probably do is something like this:
- Define a
<profile>
named eclipse (or whatever)
- Define an execution of the gmaven plugin (use this version)
- Write a short groovy script (inline in the pom or external) that checks the .classpath file for your classpath container and adds it if missing (bind execution to a lifecycle phase, e.g.
generate-resources
)
- set the profile activation to
<file><exists>${project.basedir}/.classpath</exists></file>
(because you only want it to be active in an eclipse project)
The problem with this solution: eclipse:eclipse
is a goal, not a phase, so it's not possible to execute this automatically, so you'll have to do something like this:
mvn eclipse:eclipse # two separate executions
mvn generate-resources # here, profile will be active
or perhaps this will also work:
mvn -Peclipse eclipse:eclipse generate-resources