I just ran into a similar problem and I wanted to write a full answer for others that might come across this question.
Even though the question is not about pom.xml but about command line - it does not state how to do the same with pom.xml so here it is
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>myPackage.MyMain</mainClass>
<systemProperties>
<property>
<key>myKey</key>
<value>myValue</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
For the command line - I think Sean Patrick Floyd's
answer is good - however, if you have something already defined in your pom.xml it will override it.
So running
mvn exec:java -DmyKey=myValue
should also work for you.
You should also note that the exec plugin's documentations states the following
A list of system properties to be passed.
Note: as the execution is not forked, some system properties required
by the JVM cannot be passed here.
Use MAVEN_OPTS or the exec:exec instead. See the user guide for more information.
So you can also do something like this
export MAVEN_OPTS=-DmyKey=myValue
mvn exec:java
and it should work the same way.