How do I set a system property for compiling in Eclipse?
Asked Answered
P

1

9

When I build my project from the command line with Maven, I can pass in a property using

-Dsomeproperty=true

For example:

 mvn clean package -Dsomeproperty=true

How do I do the same when building in Eclipse?

Putrid answered 11/5, 2013 at 17:37 Comment(4)
This -Dproperty means a runtime property, for example -DskipTests. You can provide these in launch configurations not in build path what you can do is provide a classpath variable or builder task in order available it in eclipse build process.Jacqui
That is a good example (-DskipTests). Could you please guide me in more details what classpath variable I should add? skipTests=true?Putrid
Which property do you want to use ?Jacqui
It is a custom one, so I guess we can just assume someproperty=true ?Putrid
G
10

You have to do the following steps (and sorry, I have no environment to prove it, just from documentation):

  1. Create a maven build by choosing on the selected pom of your project Run > Maven...
  2. Enter the relevant goal, and press add in the arguments table.
  3. Enter there your system property as name: someproperty and value: true.
  4. Then start your maven build by pressing Run.

See the following resources for details:

After having access to an Eclipse again, here are some screenshots:

  • enter image description here
  • enter image description here

The first shows how to configure an existing build (in Eclipse named a run configuration) with the relevant property. and the second shows the command that is then triggered (with the include -Dsomeproperty=true).

I do not know if there is an easy way to configure the default run configuration. You may provide an empty one, enter there the parameter, and copy then that run configuration adding the additional parameters later. The copy button is on the left top the second one (with the red rectangle marking it).

Guaranty answered 11/5, 2013 at 19:34 Comment(2)
Is there a way to add it to a "default" build? Let's say I am doing a change in a file, save it and eclipse builds it automatically - I would like that it has my -Dsomeproperty set already there. Do you know where is this "default" build configuration stored?Putrid
Have added screenshots, corrected the description, and made a suggestion how to provide a default configuration.Guaranty

© 2022 - 2024 — McMap. All rights reserved.