Launching Applications with Maven Profiles

Since Maven parents 11.2.0-SNAPSHOT it is possible to change the used LSA version and database by activating specific maven profiles.

There are the following predefined profiles:
  • dev-2tier
  • xe-2tier
  • xe-3tier
  • local-3tier
  • int-2tier
  • int-3tier
  • pro-2tier
  • pro-3tier
where dev/int/pro/xe defines the used database and 2 or 3tier defines the usage of the LSA server.

This means, that the direct dependencies of an application can always point to the current development versions.

Activation per command line

Just call mvn goals -P _profileName_ with a name listed above.

Activation in eclipse

In eclipse there are multiple ways of activating maven profiles for a project.

Permanent activation of profiles

  • Right click on the project -> select Properties
  • On the new dialog select Maven in the list on the left side
  • enter your preferred profile name (in this case mostly pro-3tier)
  • close the dialog by clicking the OK button and and click Yes on the question to update your project configuration.
In this case you will retrieve the latest released version of LSA also on compile time (see Maven Dependencies in your project, all lsa-core -client -domain artifacts will have release versions).

Please note: using method sets the correct dependencies, but does not set the needed system properties. Please also use the maven based run configuration to activate the system properties.

Run Configuration based activation of profiles

Using run configurations one can overwrite the permanent defined profile.
  • Right click on your project and choose Run As -> Maven build...
  • add goal compile exec:java
  • add your preferred profile
  • optionally: enable Resolve Workspace artifacts, otherwise you will always run against the jar files from the artifactory
  • optionally: Define a custom main class by adding the parameter name 'bundle.mainClass' as key and the qualified name of the desired main class as value (table of parameters on 'Main' tab, lower area).
    • If you do not define a custom main class, Maven uses the main class specified in your pom.xml under <properties><bundle.mainClass> by default.
    • If you forgot to specify a default main class or specified an invalid default main class (e.g. class does not exist or does not contain a main method) in your pom and do not define a custom main class, you will receive a ClassNotFoundException
  • optionally: go to the JRE tab and provide some Java VM arguments like in normal eclipse java run configurations (like -Dlog4j.configurationFile=...), please note that these VM properties may not be passed to the maven process, so if maven should be aware of these arguments, please also add them to the 'parameters table' on the main tab
  • optionally, source tab: Add your whole workspace. This is required for stopping at breakpoints while debugging. This is required even if 'resolve workspace artifacts' is checked.
  • click Run to save the run configuration and start your application
    • for the next time, your run configuration is stored in eclipse and can be reused, also for debugging (keep in mind that you might not be resolving the workspace artifacts, depending on the configuration)
Using this method one can easily change between dev and pro database and always uses the recommended code base for each database.

Run Configuration for for arbitrary projects and arbitrary main classes

It it possible to create a reusable Run Configuration that will work for any JavaFx application that also contains a public static main method which calls Application#launch() in any project.

If you use the mkws scripts after 2019-05-03, a Run Configuration called exec-java-by-type should have been already created for you, and you can choose it from your available Run Configurations.

You can also create it yourself:
  • Use the variable ${project_name} for the project name
  • Use the variable ${java_type_name} for the Maven parameter "bundle.mainClass"
  • Optional: On the "Common" tab, check "Display in favorites menu -> Run" and/or ""Display in favorites menu -> Debug" to have it always displayed at the top of the available run configuration.
exec-java-by-type.png

You can now start your application by clicking on the Java file of the class you want to run in the package explorer and choosing this Configuration from the Run Configurations in the toolbar on workbench (Note: Using Right-click -> Run As unfortunately does NOT work!).
If you initially get an error popup like "Project directory not found", select the project, then re-select the Java file, and try again.

Known Issues

  • Using a different LSA version than the projects default might lead to compile errors (e.g. API changes), which are not shown in eclipse since the projects default code base is used to compile the project using eclipse.
  • Maven exec:java handles uncaught exceptions and ignores any registered default UncaughtExceptionHandlers. This means that our default UncaughtExceptionHandler for applications, which is always registered for Fx applications (which use GsiApplicationBase) and Swing applications (which use GsiFrame), and displays uncaught exceptions in the application console and status line and logs them to our logging system, is never triggered: Any uncaught exceptions are only logged by Maven to the Java Console (Console in Eclipse) and do not show up anywhere else. This is unfortunate, because it makes such exceptions much less visible for the developer. Please make sure to check the Java Console in the IDE for uncaught exceptions, and implement proper exception handling for them.
Topic revision: r11 - 24 Mar 2021, AndreasSchaller
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback