Starting and ending Apache webserver from maven - .htaccess

I have an old web project that I'm currently mavenizing. This has been written for Apache httpd, that means a lot of rules are sitting in lots of .htaccess files (redirects, rewrites) and the pages use server side includes. I tried to use jetty with the HTAccessHandler, but this doesn't care for the rewrites/redirects. I think I now need to get to use httpd to get that properly processed, but is there a way to start apache webserver embedded from maven? Or do you know a java webserver implementation that can handle all the .htaccess properties?
Cheers,
Kai

To answer myself, I am now using the antrun plugin to start the Apache httpd binary and to call the system specific kill command with the pid file Apache is creating. I'm providing a httpd.conf file with my project where I filter maven properties including the target port, the log location and the pidfile name and location. system specific values are set by maven profiles activated by the os family. The home folder of apache httpd is to be set in the users settings.xml file. This looks like:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>Starting Apache</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="Starting Apache">
<mkdir dir="${project.build.directory}/logs" />
<echo>Starting Apache httpd:</echo>
<exec executable="${apache.home}/${apache.executable}" spawn="true">
<arg value="-f" />
<arg value="${project.build.directory}/httpd.conf" />
</exec>
</target>
</configuration>
</execution>
<execution>
<id>Stopping Apache</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="Stopping Apache">
<echo>Stopping Apache httpd:</echo>
<loadfile property="PID" srcFile="${project.build.directory}/httpd.pid">
<filterchain>
<striplinebreaks />
</filterchain>
</loadfile>
<exec executable="${kill.executable}" failonerror="true">
<arg value="${kill.argument1}" />
<arg value="${kill.argument2}" />
<arg value="${kill.argument3}" />
<arg value="${PID}" />
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>

I had a look at various newsgroups as we have the same feature request in our community
We will starting to develop a httpd-plugin in the next days. However I tried to find something at google but there seems to be no plugin that covers this topic. Developing a plugin to start and stop an apache should be fairly simple. Since Maven java it is clear to me why nearly everyone prefers tomcat or jetty.
Targeted for version 2.0 of php-maven
The Plugin will be similar to the jetty and tomcat plugin (identical goals, similar setup). The first versions will be depending on a separate installation of apache and will only setup either a virtual host or set the document root. For simple configurations and on development machines this will be ok.
Watch http://www.php-maven.org/rss.xml or https://groups.google.com/forum/?fromgroups#!forum/maven-for-php for news.
However please submit your wishes at http://trac.php-maven.org/ticket/47 (registration required) or at our google group.

Related

How deploy maven3 artifact to remote server using scp

I want to have my own maven repository for artifacts created by myself but I have a problem trying to make a deploy of maven 3 artifact to a custom server. To explain this better I'm going to give some information:
I'm using Maven 3
I'm using Eclipse Keppler
I'm using Jenkins
The remote server is running Ubuntu Server 11.04
Jenkins is running on the Ubuntu server
My local machine is running Windows XP
My first attempt was with my machine. I run Maven in Eclipse to make the deploy, and everything works fine. I add the following to my projects pom
<build>
...
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
...
</build>
...
<distributionManagement>
<repository>
<id>my server id</id>
<name>my repository name</name>
<url>scpexe://my server//path/to/my/repository</url>
</repository>
</distributionManagement>
And in my settings.xml I add
<servers>
<server>
<id>my server id</id>
<username>server username</username>
<password>server password</password>
<configuration>
<sshExecutable>plink</sshExecutable>
<scpExecutable>pscp</scpExecutable>
</configuration>
</server>
</servers>
So in my local machine it works, but I need to get this work using Jenkins. I modified the Jenkins settings.xml, because it runs on Linux, so doesn't need sshExecutable. The Jenkins settings.xml looks like
<servers>
<server>
<id>my server id</id>
<username>server username</username>
<password>server password</password>
</server>
</servers>
Then I modified the pom.xml to execute just scp and not scpexe
<distributionManagement>
<repository>
<id>my server id</id>
<name>my repository name</name>
<url>scp://my server//path/to/my/repository</url>
</repository>
</distributionManagement>
But according to this page https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes maven 3 does not support scp. I run it any way and I got the following error message from Jenkins log
mavenExecutionResult exceptions not empty
message : Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project myproject: Failed to deploy artifacts/metadata: No connector available to access repository my_repository (scp://my server//path/to/my/repository) of type default using the available factories WagonRepositoryConnectorFactory
cause : Failed to deploy artifacts/metadata: No connector available to access repository my_repository (scp://my server//path/to/my/repository) of type default using the available factories WagonRepositoryConnectorFactory
Stack trace :
If I use scpexe instead of scp I got another error message
mavenExecutionResult exceptions not empty
message : Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project pruebanueva: Failed to deploy artifacts: Could not transfer artifact {$groupId}:{$artifactId}:{$package}:{$version} from/to my_repository (scpexe://my server//path/to/my/repository): Error executing command for transfer
cause : Failed to deploy artifacts: Could not transfer artifact {$groupId}:{$artifactId}:{$package}:{$version} from/to my_repository (scpexe://my server//path/to/my/repository): Error executing command for transfer
Stack trace :
The only way I could make deploy, was doing it in two steps
Configuring Jenkins to make just the install goal
Running the following command from command line
mvn deploy:deploy-file -DgroupId=$groupId -DartifactId=$artifactId
-Dversion=$version -Dpackaging=jar -Dfile=path/to/file.jar -Durl=scp://my server//path/to/my/repository -DrepositoryId=my repository id
I tried many things, including writing that command into Jenkins goal, but everytime I use the scp command in Jenkins the build fails.
Any idea of how to solve this issue will be appreciated.
I am interested to see if there's any real Maven solutions to this. I have always fixed this using the Maven Antrun plugin as follows:
<profile>
<id>deploy</id>
<activation>
<property>
<name>deployment.server</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>deploying to server: ${deployment.server}</echo>
<taskdef classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" name="scp" />
<scp file="${project.build.directory}/${project.artifactId}.war" password="${deployment.password}" todir="${deployment.userName}#${deployment.server}:" trust="true" verbose="true" />
<!-- <sshexec command="echo unity | sudo -S cp ${project.build.finalName}.jar $( if [ -e /station ]; then echo /station/lib; else echo /opt/pkg-station*/webapps/station*/WEB-INF/lib; fi )" host="${targetStation}" password="unity" trust="true" username="wps"></sshexec> -->
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.25</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
A few notes on this: I activate this profile with a combination of running to the deploy phase, and providing a deployment.server setting. For my convenience then, I add the corresponding settings to my settings.xml so that I don't have to provide these all on the command-line every time:
<profile>
<id>alwaysActiveProfile</id>
<properties>
<deployment.server>10.10.10.10</deployment.server>
<deployment.userName>userName<deployment.userName>
<deployment.password>password</deployment.password>
</properties>
</profile>
I skip the actual deploy goal because it will be executed when I run to the deploy phase, which I don't want.
The Verhagen's answer is correct but a more pure maven solution is this: https://stackoverflow.com/a/3303525/1881318

GWT compiler behaves differently in Linux and Windows

We have a GWT application. Using Maven 3 we build and run the GWT application.
The application runs fine when we build and run on Windows 7 and test on IE on Windows. However, when we compile and run the application on Linux and then test on IE on Windows, the application looks differently.
To rule out client problems: we test on exactly the same client - Internet Explorer on Windows 7.
Further investigation revealed the Javascript on the Linux-server is differently from the Javascript on the Windows-server.
Does anyone know why GWT behaves differently on Linux and Windows? What can we do have GWT behave the same on both Windows and Linux.
We use Maven 3 to compile and run gwt.
Here's the plugin configuration of GWT:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>MyApplication.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>nl.my.app.client.Messages</i18nMessagesBundle>
<inplace>true</inplace>
</configuration>
</plugin>
and here's the module configuration:
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to=&apos;MyApplication&apos;>
<inherits name=&apos;com.google.gwt.user.User&apos; />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name=&apos;nl.my.module&apos; />
<inherits name="com.sencha.gxt.ui.GXT" />
<inherits name="com.google.common.collect.Collect" />
<inherits name=&apos;com.google.gwt.user.Debug&apos; />
<inherits name=&apos;nl.my.othermodule&apos; />
<entry-point class=&apos;nl.my.MYApplication&apos; />
<source path=&apos;client&apos; />
<source path=&apos;shared&apos; />
<set-configuration-property name="UiBinder.useSafeHtmlTemplates" value="true" />
<extend-property name="locale" values="nl_NL" />
</module>
The application is build and run using the following command:
mvn gwt:run
You probably have different JDKs on the two different systems. Ensure the JDK being used by maven is the same.
We found the problem - compatibility mode: as stated in the question the problem only occurred in Internet Explorer (IE). The compatibility mode of IE was enabled automatically when we'd access the application via a non-local address. In compatibility mode IE behaves slightly different. That's why, when we did access the application via localhost - on our development workstation - compatibility mode was not enabled by IE and the application looked like it should.
Problem was solved by adding the following in the head section of the application's single html file:
<meta http-equiv="X-UA-Compatible" content="IE=edge" >

BlazeDS: where is log file stored on server?

If I have the following in my services-config.xml file for setting up BlazeDS log file on a linux server, where does it save the log file? Or, does the output show up by default in Flash Builder 4.6 (e.g. no further info in log file)?
I've been trying to figure this out reading
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=services_logging_3.html
but haven't been able to figure it out. I must be missing something obvious. Any advice appreciated.
<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
Is there a way I can specify a location for the log file to be written?
Taken from the link you provided:
Setting the logging target
By default, the server writes log messages to System.out. In the class
attribute of the target element, you can specify
flex.messaging.log.ConsoleTarget (default) to log messages to the
standard output, or the flex.messaging.log.ServletLogTarget to log
messages to the default logging mechanism for servlets for your
application server.
So you either have to configure logging in your application server (for Tomcat: http://tomcat.apache.org/tomcat-7.0-doc/logging.html) or use something like log4j in your servlet.
services-config.xml should then look something like this:
<target class="flex.messaging.log.ServletLogTarget" level="warn">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Message.*</pattern>
<pattern>DataService.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
Sidenote: We use log4j and spring-flex, which provides org.springframework.flex.core.CommonsLoggingTarget to handle BlazeDS output.
services-config.xml
<logging>
<target class="org.springframework.flex.core.CommonsLoggingTarget" level="debug">
<properties>
<categoryPrefix>blazeds</categoryPrefix>
</properties>
</target>
</logging>
log4j.properties
log4j.appender.myAppLog=org.apache.log4j.RollingFileAppender
log4j.appender.myAppLog.File=${catalina.base}/logs/myAppLog.txt
log4j.appender.myBlazeLog=org.apache.log4j.RollingFileAppender
log4j.appender.myBlazeLog.File=${catalina.base}/logs/myBlazeLog.txt
log4j.rootLogger=DEBUG,myAppLog
log4j.logger.blazeds=ALL,myBlazeLog

Deploying an eclipse maven project in a remote linux server's tomcat

I'm looking a way to deploy a maven project developed using eclipse in a remote linux server's tomcat. I know you can export it as a .war file and dump it in CATALINA_HOME/webapps folder of the remote server. But for that you have to first export it to .war file and then copy the .war file in to remote server through SFTP or SCP. I'm looking for a way to do it with few clicks using eclipse or/and configuring some maven settings(in pom.xml or settings.xml). Does any one know how to do this? Any help is really appreciated.
The tool you are loooking for is called Tomcat Maven Plugin
What it basically does is it uses the API of Tomcat manager application, which you have to make sure is deployed on the Tomcat instance you are using. By default Tomcat manager should be available in the following location:
http://ip_of_your_linux_server:8080/manager/html
If it is not, please install it using the following command:
sudo apt-get install tomcat6-admin
You can configure the location of your Tomcat instance as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://www.mydomain.com:1234/mymanager</url>
</configuration>
</plugin>
and then run maven mvn tomcat:deploy goal. (Either from command line of from Eclipse using m2Eclipse plugin.)
Please refer to configuration and deployment pages of the plugin for more verbose information.
The most flexible solution with adapters for many different containers like Tomcat, Jetty, Glassfish, etc. is probably Maven Cargo plugin. You can find an extensive list of examples on their homepage, so no need to paste that here again.
To remotely deploy an application you'll need to configure the tomcat deployer app on the tomcat instance. Be warned, the configuration of admin users has undergone some subtle changes between tomcat 6 and 7.
Once this is working the Maven cargo plugin can deploy war files as follows:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>package</phase>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.uri>${tomcat.manager.url}</cargo.remote.uri>
<cargo.remote.username>${tomcat.manager.user}</cargo.remote.username>
<cargo.remote.password>${tomcat.manager.pass}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Additional notes
The Cargo plugin supports several different containers, problem is the doco is difficult to interpret.
I haven't used the Maven plugin. It's very new

appassembler maven plugin doesn't set "execute" permissions on generated script

The AppAssembler Maven plugin does a great job of generating distribution for me. One last problem is that the generated Shell script does not have execution permissions so I need to set them manually.
I am on Linux RedHat
Does anybody know of a clean way to set them automatically?
The only way to do this is to process the file with another maven plugin like Antrun or Assembly after running AppAssembler.
This issue (see link below) has been brought up on the AppAssembler project issue tracker and it was rejected as Won't Fix.
Issue: MAPPASM-54
I think it can be set in your assembly.xml, in the fileSet tag:
<fileSets>
<fileSet>
<directory>src/resources/bin</directory>
<lineEnding>keep</lineEnding>
<useDefaultExcludes>true</useDefaultExcludes>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.bat</include>
<include>*.sh</include>
</includes>
<fileMode>744</fileMode>
</fileSet>
...
Since Maven 3.0.3 all plugins are executed in the order they are in your pom.xml. So setting the executeable flag in a platform independet manner is as easy as using the maven-enforcer-plugin right after your appassembler plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-beanshell</id>
<phase>package</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<evaluateBeanshell>
<condition>
import java.io.File;
print("set executable for file ${basedir}/dist/bin/mql");
new File("${basedir}/dist/bin/mql").setExecutable(true,false);
true;
</condition>
</evaluateBeanshell>
</rules>
<fail>false</fail>
</configuration>
</execution>
</executions>
</plugin>

Resources