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
Related
I've packaged an application with Maven's JavaPackager plugin targetting Linux.
Everything is working fine except that I don't find how to package and install a "xxxx.desktop" file for my application.
Without this file, 1/ the icon on the launcher is ugly, 2/ the application cannot be found with a Search.
Here is my plugin's config:
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>1.6.7</version>
<configuration>
<mainClass>com.zparkingb.zploger.GUI.Zploger</mainClass>
<generateInstaller>false</generateInstaller>
<administratorRequired>false</administratorRequired>
</configuration>
<executions>
<execution>
<!-- With JRE -->
<id>bundling-for-platform-complete</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<platform>linux</platform>
<name>${project.bundle_finalname}${package.buildnamesuffix}</name>
<outputDirectory>${project.build.directory}/FULL</outputDirectory>
<createTarball>true</createTarball>
<createZipball>false</createZipball>
<bundleJre>true</bundleJre>
<customizedJre>false</customizedJre>
<!--From settings.xml-->
<jrePath>${package.jrePath}</jrePath>
<jdkPath>${package.jdkPath}</jdkPath>
<!--Special for Linux-->
<linuxConfig>
<pngFile>assets/linux/Zploger.png</pngFile>
<generateAppImage>true</generateAppImage>
<generateDeb>false</generateDeb>
<generateRpm>false</generateRpm>
<wrapJar>true</wrapJar>
<categories>
<category>Utility</category>
</categories>
</linuxConfig>
</configuration>
</execution>
</executions>
</plugin>
So I'd need to end up with file:
~/.local/share/applications/com-zparkingb-zploger-GUI-Zploger.desktop
with a similar content:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=Zploger for Scores
Icon=/home/vboxuser/Desktop/ZplogerScores/Zploger.png
Or even having the icon placed somewhere in ~/.local/share/icons/xxx/xxx and having the ".desktop" file refering to it as Icon=Zploger
How could I achieve this ?
My solution is probably far from being ideal, but I am limited in that I am building a Linux solution from a Windows environment.
The solution is based on the following principle:
Have the application startup script checking for the presence of the icons and the .desktop file in ~/.local/share/applications/.
If it doesn't exist, copy these from the package.
So the solution must
Adapt the default startup script in order to do that extra check
Add in the packaging the desktop file and the icons.
In the end, the solution is comprised of the following 4 steps:
Add to the project folder the icons and the desktop file. I've put these in a bundledata/linux/assets folder. The folder name is free but cannot be assets\ because this one is reserved for JavaPackager and cannot one of the Maven resources folder because I want these files to packaged separately.
Provide an adapted startup.sh.vtl velocity template which goal is to add to the startup script instructions to copy the icons and a valid desktop file.
The icons are copied to ~/.local/share/icons/hicolor/.
And I provide "./16x16", "./24x24", ... "./1024x1024". And also "./scalable" with a SVG version of the application icon.
The desktop file is named my-main-class.desktop (in my case com-zparkingb-zploger-GUI-Zploger.desktop) and is copied into ~/.local/share/applications/
Have that script modifying the xxx.desktop to push the current script path.
Adapt the pom.xml.
In the io.github.fvarrui.javapackager plugin's config, add the following instruction:
<additionalResources>
<additionalResource>bundledata/linux/assets</additionalResource>
</additionalResources>
My application uses log4j2 and we have two of them one for production and another for development environment. I am using maven to run the application using mvn clean jetty:run. My plugin configuration in pom.xml looks like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20171121</version>
<configuration>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>${log4j-dev.location}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
But my app still uses the log4j2.xml present in the WEB-INF/classes directory instead of the one in the log4j-dev.location path. Any ideas?
I found the solution for this problem. In the webdefault.xml file, I had to add the following code:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2-custom.xml</param-value>
</context-param>
Hope it helps somebody who spent a whole day looking everywhere like me :)
I am setting up a job in hudson to build maven based mule application on SVN , uploading to artifactory and then deploy it on cloudhub.
I am able to build project and upload it to artifactory but the problem is how to deploy it on cloudhub after that.
I have groovy post build plugin but not sure what script to write in it to proceed.
Is there anyone who could give me some pointers to proceed??
Thanks in advance
You should use mule-maven-plugin, it is the currently supported way to deploy to CloudHub via Maven. This a sample plugin configuration:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<deploymentType>cloudhub</deploymentType>
<muleVersion>3.7.0</muleVersion> <!-- This is the runtime version as it appears on the CloudHub interface -->
<username>myUsername</username>
<password>myPassword</password>
<environment>Production</environment>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
And remember to add this to your settings.xml so Maven can find the plugin:
<pluginRepositories>
<pluginRepository>
<id>mule-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
</pluginRepository>
</pluginRepositories>
You can use maven cloudhub-maven-plugin. Please refer details at cloudhub-maven-plugin
Hope this helps.
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
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.