Reputation: 2403
I'm using eclipse juno & maven 2.2.1.
Is there a simple way for separating eclipse output folder with the one of maven ? So I'd like to have eclipse building in the target directory and maven in the target-maven directory.
I tried using
<directory>target-maven</directory>
in the pom.xml.
It's working fine if I do that after creating the project.
But when recovering the project from svn (without .classpath .target ... only src folder) followed by eclipse:eclipse, everything is building in target-maven.
Upvotes: 2
Views: 4745
Reputation: 10538
Sort of in response to the first answer, here is a legitimate reason to have separate output folders for Maven and Eclipse:
I'm trying to work on a rather large Maven-based project (200+ subprojects) involving the latest Scala (2.13), which is not supported in Eclipse. Scala-IDE is effectively dead at 2.12. Without it, doing a clean build in Eclipse will delete the Maven-compiled Scala classes and break everything oh so thoroughly. I'm not sure if I need to mention that m2e is unusable, too.
So it all ended with a few lines of perl to fix my workspace. Believe me, I have tried a lot of other approaches. This solution still requires me to supply the compiled Scala classes to Eclipse in another scripted step, but that's not really an issue at this point.
This solution will not change Maven's, but Eclipse's output folders by adjusting .classpath
files generated by mvn eclipse:eclipse
. Change the target folder in the call to setAttribute(...)
to your liking and run the script in the project root.
#!/usr/bin/perl
use strict;
use XML::XPath;
my $files = [];
find_files( '.', '^\.classpath$', $files );
for my $file ( @$files ) {
my $xp = XML::XPath->new( filename => $file );
$xp->find( '/classpath/classpathentry[@kind="output"]' )
->[0]
->setAttribute( 'path', 'target-eclipse' );
open my $ofh, '>', $file or die 'Cannot open for writing: '.$file;
print $ofh $xp->getNodeAsXML;
close $ofh;
}
sub find_files {
my ( $path, $mask, $hits ) = @_;
opendir my $dh, $path or die 'Cannot open path: '.$path;
for my $entry ( grep { ! /^\.{1,2}$/ } readdir $dh ) {
my $fullpath = $path.'/'.$entry;
if ( -d $fullpath ) {
find_files( $fullpath, $mask, $hits );
} elsif ( $entry=~/$mask/ ) {
push @$hits, $fullpath;
}
}
closedir $dh;
}
Update: If you don't mind regenerating all of Eclipse's files (which will wipe any other custom settings you might have), you can simply do this:
mvn eclipse:eclipse -DoutputDirectory=target-eclipse
Upvotes: 0
Reputation: 13556
You can create different profiles for this. Create a profile mvn-eclipse
for Eclipse and mvn-cmd
for the command line where you specify different target directories. You need to activate the profiles in the Eclipse Launch Configurations (select Run as -> Maven Build ...
and theres the Profiles
field) or you may create two different settings.xml
. In one you specify
<activeProfiles>
<activeProfile>mvn-eclipse</activeProfile>
</activeProfiles>
and in the other
<activeProfiles>
<activeProfile>mvn-cmd</activeProfile>
</activeProfiles>
You should name the settings file that contain mvn-cmd
as an active profile settings.xml
, so that you don't have to make any changes when using maven on the command line. In Eclipse you can specify the settings via Preferences -> Maven -> User settings
.
However I don't recommend this, since you may run into trouble with both output folders running out of sync. So be sure to have a good reason for this.
Upvotes: 2