Maven profiles are not considered in Eclipse - eclipse

I have three profiles defined in my pom.xml:
<profiles>
<profile>
<id>ABC</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<url.base>http://server1.de</url.base>
<url.searchevse>/search</url.searchevse>
<url.reservation>/reservation</url.reservation>
<url.cancelation>/reservation/cancel</url.cancelation>
<xxx.devmode>false</xxx.devmode>
</properties>
</profile>
<profile>
<id>XYZ</id>
<properties>
<url.base>http://server2.de</url.base>
<url.searchevse>/cns/search</url.searchevse>
<url.reservation>/cns/reservation</url.reservation>
<url.cancelation>/cns/cancel_reservation</url.cancelation>
<xxx.devmode>false</xxx.devmode>
</properties>
</profile>
<profile>
<id>DEVELOPMENT</id>
<properties>
<url.base>http://localhost/noservices</url.base>
<url.searchevse>/no/search</url.searchevse>
<url.reservation>/no/reservation</url.reservation>
<url.cancelation>/no/cancel_reservation</url.cancelation>
<xxx.devmode>true</xxx.devmode>
</properties>
</profile>
</profiles>
In Eclipse I have a Run Configuration
clean install XYZ
and I tried both using -PXYZ (and -P XYZ) in the Goals field as well as
clean install
in the Goals field and XYZ in the Profiles field.
The problem:
The defined profile is never used.
Inserting the active profile under Properties-->Maven-->Active Maven Profiles doesn't work (or do I have to use a special syntax, e.g. no spaces after a comma or so).

Right click your project in the Project Explorer then go to
Properties --> Maven --> Active Maven Profiles
and type in only the profile name that you want to run.
If you want to run your ABC profile, type in ABC in the Active Maven Profile input box.
The description(separated by commas) given there is a bit confusing.
Once you define your profile name or id in the input box. You can clean and run your project on your server.
By doing so, your mentioned active maven profile will be run.

verify that plugin execution id are not equal in different profiles

For those who still have problems. I am not really used to Eclipse nor STS but I actually use Spring Tool Suite Version: 4.7.1.RELEASE. I think the Active Maven Profile input box. may be named Write here your already activated Maven Profile :) as I think its purpose is to select an activated profile to run.
In my case, what I did was :
edit my Maven settings.xml (maven folder, conf folder) file to activate the desired profile with <activeProfile>MyProfileId</activeProfile> in the activeProfiles section. The one thing I really appreciate is that it accepts profile even defined in your project pom.xml and that is great for peoject with sub modules. If you have time, read this https://maven.apache.org/guides/introduction/introduction-to-profiles.html
Then add your profile to Active Maven Profile input box (Ctrl+Alt+P or right click on your project, Maven, Select Maven profiles). You can also deactivate a profile with ! or - before a profile name.
You might need to restart Eclipse.
The first step is only to activate your profile. So if you have any way to achieve this, feel free to do as so.

In Eclipse 4.20 you can right click on project -> Maven -> Select Maven Profiles...

Related

How can I configure Maven (command line) and the IDE to build in different folders?

I'm often switching between my IDE (running just the unit tests for the code which I'm working on) and the command line (running all unit tests).
This causes problems: Sometimes, mvn clean fails because the IDE is building the code. Or I get weird errors in the IDE about missing classes because the IDE is reading files which Maven has modified.
Also, I can't continue working in the IDE why Maven builds in the background.
How can I configure my IDE or Maven to use different build folders?
Use profiles and this code in your (parent) POM:
<project>
...
<build>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>
</build>
<properties>
<target.dir>target</target.dir>
</properties>
<profiles>
<profile>
<id>ide-folders</id>
<properties>
<target.dir>target-ide</target.dir>
</properties>
</profile>
</profiles>
...
Configure the project in your IDE to enable the profile target-ide when building. Now Maven and the IDE use different folders.
Alternatively, you could enable this profile in your settings.xml and make the folder target-ide the default. This way, you wouldn't have to modify the settings of many projects in your IDE. It would even work on your CI build server (it would build into target-ide but who cares? And if you cared enough, you can enable the profile there as well).
Note: This is based on a blog-post on jroller.com which is down. The Internet Archive has a copy: https://web.archive.org/web/20150527111413/http://www.jroller.com/eu/entry/configuring_separate_maven_output_folders

Eclipse launch profile - Ask for user prompt

I have an Eclipse launch file like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<stringAttribute key="M2_GOALS" value="clean appengine:deploy" />
<stringAttribute key="M2_PROFILES" value="development" />
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc}" />
</launchConfiguration>
This file is related to a Google App Engine Maven project, which I'm using to deploy the application to the online environment.
Because different environments (dev, stage, prod, ...) have different configurations, I'm using Maven profiles in order to manage them.
This launch file works fine but I'm unable to easily configure the version to be used for deploy. I have a Maven property in pom.xml file which allows me to deploy a specific version, but it is not very handy
<app.deploy.version>this-is-my-version</app.deploy.version>
Is there a way to configure .launch file on asking an user input and then configure that input as a Maven property related to the goal I'm using?
EDIT
I will now generalize and better focus the question:
during a Maven build, does exists a plugin or something that asks for an user input directly from the CLI where the build is running? And can this input be configured as a Maven property which can be used right after while the build is running?
This can be a very generic plugin, a parameter in the goal defines the name of property to be configured with the given input.
Related to my need, an user input will be the version of deployment, and need to be configured as app.deploy.version during build.
Something like:
...
...
insert value for property 'app.deploy.project'
input: my-value
'app.deploy.project' set to 'my-value'
...
...
Maven profiles are able to set Maven properties. For example, the following profile sets the os-jvm-flag property when the build is run on MacOS.
<profiles>
<profile>
<id>macosx-jvm-flags</id>
<activation>
<os><family>mac</family></os>
</activation>
<properties>
<os-jvm-flags>-XstartOnFirstThread</os-jvm-flags>
</properties>
</profile>
</profiles>
If you want to prompt for a version wehen using the Maven launcher from Eclipse, you might be able to use Eclipse's variable expressions. Add a parameter to the Maven launcher page that uses a variable and specify a string_prompt expression.

Activating a settings.xml Defined Maven Profile From POM File

Our enterprise team maintains a settings.xml file that defines various profiles that development projects can use with Maven to build their artifacts and install them in a repository. The expectation is that each project in Jenkins would define a -P parameter with the desired profile specified.
Here is my issue: The profile I need to use specifies a repository that is normally not visible to my project (a staged release repository), so anything in that repository cannot be depended upon without that profile being active. I need a way to activate that profile defined in settings.xml in my project's pom.xml file. Otherwise, when looking at my project in Eclipse, errors are shown in the pom.xml that dependencies cannot be resolved because the profile isn't active to make the repository visible.
Is there a way to activate a settings.xml defined profile in a pom.xml file? Alternatively, is there a way to tell Eclipse to always activate a profile for a particular project?
You can use the activateByDefault tag to specify a default profile to use:
<profile>
<id>ProfileToActivate</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
After more research, I found a project specific Maven property in Eclipse where I can set the active profiles. You can set this by right-clicking on the project, select "Properties", and select "Maven". You are presented with a text entry box for "Active Maven Profiles (comma separated):".
That solved my problem.
I was looking for a more global solution in Eclipse rather than at the project level. But this seems to work.

Eclipse on-click deploy to remote Tomcat

I've been looking for this all-over the internet and somehow I can't find a easy way to do it.
What I need is really simple and I believe that many of you probably do it already:
- I develop Java Web Apps in Eclipse and so does my team;
- we have a tomcat7 server running on a Ubuntu machine which works as a centralized Dev environment;
- I would like to click a deploy button and send the new data to the server and deploy it (reload it), instead of exporting a war every time and manually upload it to server.
Up till now seems like the only way to do it is with Maven plugin for eclipse, which uses the manager/HTML interface of tomcat.
Problem: I just can't get it to work. But somehow I can't find a simple walk through that explains how to do it. I'm not too experienced with eclipse or Linux but the configuration of local tomcat servers seems pretty straightforward. I don't understand why is so hard to install a remote one.
Could you please help me out by explaining in detail how to do it? Thank you in advance for you patience.
Yes, you can use Tomcat7 Maven Plugin. Here is the steps:
1) Install Maven Integration for Eclipse (m2eclipse) to your eclipse from Eclipse Marketplace etc.
1.1) Navigate to Help -> Eclipse Marketplace and search "Maven Integration for Eclipse".
2) From eclipse, create a maven project.
2.1) Navigate to File -> New -> Project... -> Maven -> Maven Project.
2.2) Click Next (Leave all fields with default).
2.3) Select "maven-archetype-webapp" and click Next.
2.4) Enter arbitrary value on Group Id and Artifact Id. (e.g. "org.myorg" for Groupd Id and "myapp" for Artifact Id) and click Finish. (You will see pom.xml in your project's root.)
3) Edit pom.xml like this: (Replace yourhost below with your hostname or ip address.)
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://yourhost:8080/manager/text</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
4) Add following lines to your CATALINA_BASE/conf/tomcat-users.xml and restart your tomcat.
<tomcat-users>
...
<role rolename="manager-script"/>
<user username="admin" password="" roles="manager-script"/>
</tomcat-users>
5) From eclipse, run tomcat7:redeploy goal.
5.1) Right click your project and navigate to Run As -> "Maven build...".
5.2) Enter tomcat7:redeploy to Goals and click Run.
6) Once you create the run configuration setting above, you can run tomcat7:redeploy goal from Run -> Run Configurations.
Please refer to the following documents for details:
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
http://tomcat.apache.org/maven-plugin-2.1/index.html
http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html
If you use another user instead of admin with empty password (which is plug-in's default), you need to create %USERPROFILE%.m2\settings.xml and edit pom.xml like below:
%USERPROFILE%.m2\settings.xml:
<settings>
<servers>
<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
%USERPROFILE% is your home folder. (e.g. C:\Users\yourusername)
pom.xml:
<configuration>
<server>tomcat7</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
Add server tag.

How do I import an alternative pom.xml file in m2eclipse

The only possible input is a directory where m2eclipse will automatically scan for pom.xml. What if you want to import an alternative file (say abc.xml)? can it be done and how?
Thank you for your time.
No, it's not possible. m2e relies on the presence of a pom.xml. The only way to have a different behaviour in m2e is to use maven profiles. The following will be activated automatically when using m2e :
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
...
</profile>
Your CLI builds will remain unaffected, unless you manually use the m2e profile.
Maven is pretty dependent on the pom.xml keeping it's name; repos, developers and other tools expect it to be there for a maven project.
in the eclipse navigator view, right click on your project and click new->file
click advanced and check off "link to a file in the file system" and specify the path