0

I am using the maven jetty pluggin as follows:

 <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.5.v20120716</version>
    <configuration>
      <stopKey>1</stopKey>
      <stopPort>9999</stopPort>
    </configuration>
  </plugin>

My web app is running on ec2 where we have a few environment variables setup (like CLOUD_DEV_PHASE). I was wondering if there is a way to put a dummy value for CLOUD_DEV_PHASE in the pom file so you don't have to do it on your system. Is there a way to do this?

I am looking for something similar to

CLOUD_DEV_PHASE=dev mvn jetty:run
ekaqu
  • 1,860
  • 2
  • 22
  • 34

4 Answers4

3

you means add system property? like this:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <systemProperties>
      <systemProperty>
         <name>CLOUD_DEV_PHASE</name>
         <value>dummy</value>
       </systemProperty>
    </systemProperties>
    <webApp>
      <contextPath>/test</contextPath>
    </webApp>
   </configuration>
</plugin>

for more info, check : http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Setting_System_Properties

Zava
  • 713
  • 6
  • 17
  • No, it has to be a Environment Variable. the following works: CLOUD_DEV_PHASE=dev mvn jetty:run – ekaqu Nov 29 '12 at 02:48
1

I'm not sure to completely understand your question, but if you need to set an environment variable, I usually use the exec plugin : http://mojo.codehaus.org/exec-maven-plugin/

The following goal : http://mojo.codehaus.org/exec-maven-plugin/exec-mojo.html

Someting like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
      <execution>
        <id>setEnvVar</id>
        <phase>initialize</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>export</executable>
      <arguments>
        <argument>CLOUD_DEV_PHASE=Something</argument>
      </arguments>
    </configuration>
  </plugin>

Regards

xavier.seignard
  • 10,084
  • 12
  • 44
  • 71
  • I tried this and export is not a command but a bash function so exec:exec isn't able to call it this way. Ill see if there is a way – ekaqu Nov 29 '12 at 02:56
  • I tried src/main/config/environment.sh which just exports but since the process is forked it doesn't get added. – ekaqu Nov 29 '12 at 03:03
  • Did you tried with exec:java? http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html during compile phase? – xavier.seignard Nov 29 '12 at 12:49
  • you mean setting the environment variable in java code and have exec:java call that? I found [http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java](this page) that might be able to do the trick. – ekaqu Nov 29 '12 at 17:53
1

I saw this one in a forum. I hope it works on you.

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
      ...

      <env>
         <wibble>pencil</wibble>
         <foo>bar</foo>
         <black>white</black>
      </env>

      ...

    </configuration>
</plugin>
Mnick
  • 213
  • 3
  • 15
  • It works! Thanks! Please note though that in my experience you should use "jetty:run-forked" goal instead of "jetty:run". – pawel Jun 05 '19 at 13:09
0

I would try to set the property env.CLOUD_DEV_PHASE in the project section:

<project>
    ...
    <properties>
        <env.CLOUD_DEV_PHASE>dev</env.CLOUD_DEV_PHASE>
    </properties>
    ...
</project>

or in the Jetty plugin configuration:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    ...
    <systemProperties>
      <systemProperty>
         <name>env.CLOUD_DEV_PHASE</name>
         <value>dev</value>
       </systemProperty>
    </systemProperties>
   </configuration>
</plugin>
halfer
  • 18,701
  • 13
  • 79
  • 158
benweet
  • 3,445
  • 1
  • 19
  • 26
  • So I tried adding the properties to the pom and it doesn't seem that the jetty JVM will see it. – ekaqu Apr 11 '13 at 20:47
  • I then tried systemProperty env.CLOUD_DEV_PHASE and the java system property of env.CLOUD_DEV_PHASE exists but its not in the environment variables list – ekaqu Apr 11 '13 at 20:49