Specify which "running" profile to use with jetty

1,280 views
Skip to first unread message

Shadowwalker

unread,
Mar 28, 2012, 3:45:27 PM3/28/12
to maven-...@googlegroups.com
I'm having a little issue with my Zend Maven app :
I need to set different "profiles" to run my app depending on which step of development I'm at : development, testing, acceptance, preproduction ,production
and I need to find a way to tell jetty to use a specific profile when running "mvn jetty:run" command so that maven can retrieve the right configuration file in my project for jetty :

Here's the profile config in pom.xml :

<profiles>
        <profile>
            <id>development</id>
            <properties>
                <zend.environment>development</zend.environment>
            </properties>
        </profile>
        <profile>
            <id>testing</id>
            <properties>
                <zend.environment>testing</zend.environment>
            </properties>
        </profile>
        <profile>
            <id>integration</id>
            <properties>
                <zend.environment>integration</zend.environment>
            </properties>
        </profile>
        <profile>
            <id>acceptance</id>
            <properties>
                <zend.environment>acceptance</zend.environment>
            </properties>
        </profile>
        <profile>
            <id>preproduction</id>
            <properties>
                <zend.environment>preproduction</zend.environment>
            </properties>
        </profile>
        <profile>
            <id>production</id>
            <properties>
                <zend.environment>production</zend.environment>
            </properties>
        </profile>
    </profiles>


And here's my jetty plugin configuration in pom.xml :

<plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${maven.jetty.plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                        <version>${ch.qos.logback.logback-classic.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.phpmaven</groupId>
                        <artifactId>maven-php-jettycgi</artifactId>
                        <version>${maven.php.jettycgi.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <webXml>${project.basedir}/target/classes/webapp/WEB-INF/web.xml</webXml>
                    <webAppSourceDirectory>${project.basedir}/target/classes/public</webAppSourceDirectory>
                    <systemProperties>
                        <systemProperty>
                            <name>logback.configuration</name>
                            <value>${project.basedir}/target/classes/etc/logback.xml</value>
                        </systemProperty>
                        <systemProperty>
                            <name>phpIncludePath</name>
                            <value>${project.basedir}/target/php-deps/library;${project.basedir}/target/php-deps</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>

Can anybody help me ?
Thanks.

martin.eisengardt

unread,
Mar 28, 2012, 5:02:10 PM3/28/12
to maven-...@googlegroups.com
This will be part of php-maven 2.1
 
 
But you can use a workaround. Typically zend applications are using environment variable 'APPLICATION_ENV' to determine the staging. I am assuming you are using Zend_Application.
To add an environment variable to jetty edit the resources/WEB-INF/web.xml. Add the following nearby the other parameters:
<init-param>
    <param-name>ENV_APPLICATION_ENV</param-name>
    <param-value>testing</param-value>
</init-param>
Thats the static version.
 
 
 
How make it  dynamic? On command line (this would be the jetty:run command) you can active a profile via:
mvn -P production <command>
But that will only activate the profile. You now need to make the web.xml dynamic. That's simple:
<init-param>
    <param-name>ENV_APPLICATION_ENV</param-name>
    <param-value>${zend.environment}</param-value>
</init-param>
The last change is to activate resource filtering read http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
 
After activating the filtering the command "mvn -P production clean compile jetty:run" will produce the correct environment variable. Test it with die(getenv('APPLICATION_ENV'));
 
 
Thats all.
 
 
Greetings
Martin
 



--
You received this message because you are subscribed to the Google Groups "Maven for PHP" group.
To view this discussion on the web visit https://groups.google.com/d/msg/maven-for-php/-/LEzGYQiP2gwJ.
To post to this group, send email to maven-...@googlegroups.com.
To unsubscribe from this group, send email to maven-for-ph...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/maven-for-php?hl=en.

Shadowwalker

unread,
Mar 30, 2012, 10:20:00 AM3/30/12
to maven-...@googlegroups.com
Ok
What about specifying which profile to use when running mvn clean test ? Is there anyway to force the use of on the declared profiles form pom.xml ( without using the -P option manually) ?
To unsubscribe from this group, send email to maven-for-php+unsubscribe@googlegroups.com.

martin.eisengardt

unread,
Mar 30, 2012, 10:40:44 AM3/30/12
to maven-...@googlegroups.com
There is no way. Hmmm. Or let me say it is not easy. You can - of course - write down a custom profile activator. And you may even fetch the goal one is executing and set a proper profile. But for me this seems to be a very ugly hack to only manipulate the staging.

For zend applications you should write down all config in a single application.ini file. This leads you to the question how to enable the proper staging via ENV-Variable.
I already showed a way you can influence the environment variable for the jetty servlet (=the website in browser).

To influence it for unit testing you can either use the 'testing' staging within the setup class of the testcase or you can use the following snippet:
<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.phpmaven</groupId>
      <artifactId>maven-php-phpunit</artifactId>
      <configuration>
        <executableConfiguration><env><APPLICATION_ENV>testing</APPLICATION_ENV></env></executableConfiguration>
      </configuration>
    </plugin>
    ...
  </plugins>
  ...
</build>

What exactly do you want to do? Can you give me an exact example of what should happen during the lifecycle? Maybe I can help you with a workaround.


Some hint: In the 2.1 planning draft I already identified the problem that there may be different versions of the code because of the configuration, one for local developers, one for being stored in repositories, one for productional server.


To view this discussion on the web visit https://groups.google.com/d/msg/maven-for-php/-/vfsNEmAlgeMJ.

To post to this group, send email to maven-...@googlegroups.com.
To unsubscribe from this group, send email to maven-for-ph...@googlegroups.com.

Shadowwalker

unread,
Mar 30, 2012, 10:46:23 AM3/30/12
to maven-...@googlegroups.com
What I'm trying to do is to use a special conf directory in my maven project architecture in which I have a directory for each profile declared.

In each of theses "profile directories", I intend to put a INI file (always named the same way regardless of in which profile doirectory it is). This file is meant to be loaded by maven in the right place using this line in pom.xml

<resource>
                <directory>${project.basedir}/src/conf/${zend.environment}</directory>
            </resource>

But I would like to be able to make sure that the profile used when running mvn test will be the following one without having to use the -P option in my cli call :

<profiles>
        ...

        <profile>
            <id>testing</id>
            <properties>
                <zend.environment>testing</zend.environment>
            </properties>
        </profile>
        ...
</profiles>

martin.eisengardt

unread,
Mar 30, 2012, 10:51:43 AM3/30/12
to maven-...@googlegroups.com
This scenario is not yet supported. As a workaround you should use the above example using the APPLICATION_ENV variable. This is the "zend-way" and officially supported by zend I guess.

However we will support this scenario in future versions of php-maven. But now with profiles directly. We will introduce a way to manipulate configurations on-the-fly. This means: A special plugin (f.e. maven-php-configurator) can be enabled. By the help of this plugin it will rewrite the configuration files before invoking package/install/deploy, test or site.

ryan.r...@gmail.com

unread,
Mar 30, 2012, 12:10:10 PM3/30/12
to maven-...@googlegroups.com
Mmm that means that i have no choice but to specify it manually. I forgot to mention that those profile directories would also contain the connection configuration parameters for the app's db depending of which environment (profile) we're in.

Well i think i will make some use of the eclipse run configurations functionality (one of my collegues has already done so with his java projects) and i'll share a temporary workaround until another way is put in place.

Another thing I wanted to ask about is the continuous integration... Any plans on building something for that? I mean with the use of a dedicated server like atlassian bamboo or jenkins and so on.

Cheers,
Ryan.
From: "martin.eisengardt" <martin.e...@googlemail.com>
Date: Fri, 30 Mar 2012 16:51:43 +0200
Subject: Re: Specify which "running" profile to use with jetty

This scenario is not yet supported. As a workaround you should use the above example using the APPLICATION_ENV variable. This is the "zend-way" and officially supported by zend I guess.

However we will support this scenario in future versions of php-maven. But now with profiles directly. We will introduce a way to manipulate configurations on-the-fly. This means: A special plugin (f.e. maven-php-configurator) can be enabled. By the help of this plugin it will rewrite the configuration files before invoking package/install/deploy, test or site.

--
You received this message because you are subscribed to the Google Groups "Maven for PHP" group.
To post to this group, send email to maven-...@googlegroups.com.
To unsubscribe from this group, send email to maven-for-ph...@googlegroups.com.

martin.eisengardt

unread,
Mar 30, 2012, 1:38:10 PM3/30/12
to maven-...@googlegroups.com
You mean hosting a hudson for your project? We already have one that will be available for users soon.
 
 
Or do you mean ci integration itself?
Every CI server that is aware of maven should be able to handle php-maven projects per default. However there are some features and possible performance speed ups that require a php-maven plugin.
 
 
To answer your question: Both is planned. We will host projects including CI and we will - one day - provide plugins for CI servers to extend the functionality.

ryan.r...@gmail.com

unread,
Mar 30, 2012, 2:54:24 PM3/30/12
to maven-...@googlegroups.com
What i actually meant is that if i were to install a ci server (say hudson for example) would I need to do some special manipulations for my maven php projects to be run in the same way a usual maven project would?

From: "martin.eisengardt" <martin.e...@googlemail.com>
Date: Fri, 30 Mar 2012 19:38:10 +0200

martin.eisengardt

unread,
Mar 30, 2012, 3:10:52 PM3/30/12
to maven-...@googlegroups.com
No, you don't need special setup. Ensure that PHP executable is found. On our hudson we are able to choose various php installations to test libraries against them (not only against one version). But this is not yet for public use.
 

Shadowalker

unread,
Sep 6, 2012, 8:55:47 AM9/6/12
to maven-...@googlegroups.com, martin.e...@googlemail.com
Hi,
Is there somewhere a tutorial on the configuration of an hudson/jenkins configuration to be used with mavenphp projects ?
If not, could you provide one ?
Cheers.
Reply all
Reply to author
Forward
0 new messages