简体   繁体   中英

How to add environment variables to maven-jetty-plugin

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

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

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

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM