I have a maven project. As activeByDefault
I have the production profile. It seems I can't find a way to run it as application in Eclipse using the staging profile unless I put the activeByDefault
in the staging profile.
Is there a way to configure this so I don't have to edit the pom every time?

- 67,400
- 29
- 193
- 254

- 7,140
- 12
- 75
- 120
-
Good question. I have no idea exactly what Eclipse is executing when you say "Run as Java application" on a Maven project. Presumably it just fires up the version its compiling in the background, which would be based on your default profile? What happens if you explicitly build a different profile (via Run as... Maven build...) and then execute the app? – Duncan Jones Jan 17 '13 at 15:39
1 Answers
The only thing is affected in running Java app from Maven project in Eclipse is how application classpath is constructed. Generally in Maven there are several different classpaths scopes: compile, compile tests (this one is actually used to construct classpath in Eclipse JDT) and runtime. The runtime classpath scope is used to assemble classpath for the application launch. The m2e is actually using Maven code to resolve it.
So, you either have to change profile activation settings in your pom.xml or specify active profile in Eclipse project properties / Maven / Active Maven Profiles.
If you want runtime profile to be different from build-time profile in Eclipse, it is not possible right now. You'll have to submit an enhancement request for m2e to allow to specify active profiles when calculating launch classpath.

- 31,461
- 5
- 66
- 67
-
To expand your first suggestion - I guess the OP could define that the staging profile is activated upon the presence of a system property. Then include that property in the "Run as Java application" parameters? – Duncan Jones Jan 17 '13 at 16:00
-
@DuncanJones exactly. I would like to have something to create like a "running" profile for the staging environment. – dierre Jan 17 '13 at 16:15
-
If the 'environment' is a different user, or machine, it would make sense to activate the profile in the settings.xml local to that machine/user. If the environment is just something you tinker with ad-hoc, I suppose it should be a property in the pom.xml. – cmonkey Jan 17 '13 at 18:47
-
Adding that property to execution profile won't work. Those properties are passed to the Java app and by that time classpath is already resolved. I've updated my answer. – Eugene Kuleshov Jan 17 '13 at 20:56
-
I usually do like that. First, I try to put all info depending on the environment in a file, let's call it config. Then I create a folder in the project for each environment I need, i.e.: env-dev/, env-prod/, etc. In each folder I put a copy of config, properly edited to reflect the env constraints. When I run the app from within Eclipse, I manually add the env-dev/ to the project classpath, while when I build the app for release through maven I explicitly specify a profile through -P to include the config from the env folder I'm interested in. I know... not so Maven-way. – danidemi Nov 16 '14 at 11:26