How to deploy a maven web application in ftp? - maven

I am building a web project using spring framework and maven. I want to deploy it using ftp.
For this I have included the apache weagon :
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://ftp.xxxxx.com</url>
</repository>
</distributionManagement>
<build>
<!-- FTP TRANSFER -->
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-5</version>
</extension>
</extensions>
and I have also created a file settings.xml
<settings>
<servers>
<server>
<id>ftp-repository</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
</settings>
But when I execute mvn deploy I get the following error:
Authentication failed, Password not specified for the repository ftp-repository.
Is this the correct way to deploy an app?
What else should I do to deploy it successfully?

For completeness sake, I have had this issue when i tried to connect to an sftp server using the default ftp 'wagon'. When I changed the artefactId to wagon-ssh (also see this link) the messages started to make more sense.
In other words; the error message is not very helpful in this particiular case.

Related

Maven FTP Deployment: Unable to create directory

For the past couple of hours, I have been unable to solve this issue. Note that I have tried looking for solutions with no avail.
Anyway, my issue is that I am unable to create a directory with the Maven Wagon plugin. Here is an snip of the error for reference.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project spigotsite:
Failed to deploy artifacts: Could not transfer artifact be.maximvdw:spigotsite:jar:0.0.12-20160523.053812-1 from/to public (ftp://***.***.***.***): Unable to create directory be -> [Help 1]
Snip of pom.xml
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>public</id>
<name>Repository</name>
<url>ftp://***.***.***.***</url>
</repository>
</distributionManagement>
Snip of settings.xml
<servers>
<server>
<id>public</id>
<username>***</username>
<password>***</password>
</server>
</servers>
I have verified that I am able to log onto the FTP and create a directory. I gave the FTP user full write permission to the folder as well as tested writing to the folder itself. I seem to be overlooking something and I appreciate if anyone could point out my mistake. Thank you in advance.
It worked for me:
POM.xml
<build>
...
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>3.0.0</version>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://...myhost.../srv/ftp/</url> <!-- repository location -->
</repository>
</distributionManagement>
SETTINGS.xml
<servers>
<server>
<id>ftp-repository</id>
<username>myusername</username>
<password>mypassword</password>
<configuration>
<endpointChecking>false</endpointChecking>
</configuration>
</server>
...
</servers>

OSGi: how to use PuTTY scp with maven-bundle-plugin

I want to deploy my maven compiled OSGi bundle to my remote OSGi repository. I'm on Windows 7 and use the maven-bundle-plugin (2.3.7) from eclipse. The repository is on linux and is accessed over ssh.
I have configured in settings.xml to use plink and pscp (Putty tools) to do the ssh work.
In <distributionManagement> I set the repository url, which starts with scpexe://
The maven-deploy goal works fine and uploads the jar files and metadata.xml to the repository.
Now I also want the OBR metadata to be produced and uploaded. I thus add in the configuration of the maven-bundle-plugin, <remoteOBR>my-repository</remoteOBR> (which is the same ID as the repository in <distributionManagement>.
When executing deploy, (after the maven deploy phase finishes successfully), I get the error.
[ERROR] Failed to execute goal
org.apache.felix:maven-bundle-plugin:2.3.7:deploy (default-deploy) on
project bootstrapper: Transfer failed: Exit code: 1 - 'scp' is not recognized as an
internal or external command, operable program or batch file.
-> [Help 1]
This means that the maven-bundle-plugin does not use the pscp command as specified in settings.xml, but rather "scp", which is not available on the path.
How can I configure the maven-bundle-plugin to upload the OBR data using PuTTY's pscp?
I eventually found a working solution:
don't use the external ssh tool (PuTTY), but only the maven-internal ssh/scp implementation
thus, use wagon-ssh (not wagon-ssh-external)
add username, private key location and passphrase to settings.xml (sadly, cannot use pageant, but must hardcode my passphrase in settings.xml (beuh) )
So the POM looks like (note, scp:// protocol is used for the url)
<project>
...
<distributionManagement>
<repository>
<id>my-repository</id>
<url>scp://repo.myserver.com/path/to/repo/</url>
</repository>
</distributionManagement>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
...
<remoteOBR>my-repository</remoteOBR>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.5</version>
</extension>
</extensions>
</build>
...
And settings.xml (which is located at C:\Users\myUsernameOnWindows\.m2\)
<settings>
<servers>
<server>
<id>my-repository</id>
<username>myUsernameOnRepo</username>
<privateKey>C:/path/to/private/key/id_rsa</privateKey>
<passphrase>myPrivateKeyPassphrase</passphrase>
</server>
</servers>
</settings>

Maven deploy .jar to network location

How can I deploy a .jar to a network path? I'm looking at maven-deploy-plugin and other examples and keep finding things about deploying to tomcat, glassfish and ftp. My needs are simpler. I only need to deploy to a network path.
Bonus: After running a network path, is it possible to run console commands on an external windows command prompt?
The maven-deploy-plugin is intended to deploy an artifact to a repository which means usually to a repository manager (Artifactory, Nexus, Archiva etc.). The things you are talking about can be handled by the tomcat6- or tomcat7-maven-plugin which support the things you need. Other containers like Glassfish can be handled by cargo2-maven-plugin. I'm not aware of a up-to-date glassfish-maven-plugin only this one maven-glassfish-plugin which looks out of date (Take a look here).
If you like making deployments via ftp you can use the following configuration for the maven-deploy-plugin:
<project>
...
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://repository.mycompany.com/repository</url>
</repository>
</distributionManagement>
<build>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
</build>
...
</project>
<settings>
...
<servers>
<server>
<id>ftp-repository</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
...
</settings>
But this is in contradiction to the idea of Maven.
You can try to use the deploy-file goal of the maven-deploy-plugin to see if this would be option to deploy to a network path. I'm not sure if this will work.

Maven cannot find dependencies from remote nexus repository

I had to migrate from a older Nexus server to Nexus OSS v2.0.4 today. I have been facing strange issues from the morning. Firstly I installed nexus and started it, and I was able to browse it from the server machine only once and then no more. But later from all other machines in the network I could access the server (using http://remote.hostname:8081/nexus ).
Then I copied all the contents of the storage directory from the old server machine and pasted them one by one into the new machine. (For every repository, created a repository in the new server and gave the local storage Location as the directory which i copied from the old server). Now I am able to see all the jars which I had, but when I try to use them from maven, I am not able to do so. Meaning, if i try to run a maven project, then it says dependencies not found. I can see that it is looking for jar exactly in the place where it lies in the new server, but fails to download it. Any idea why it is not able to download the jars?
Also I am still not able to access the new nexus server from the server machine's browser, why is it so? Any suggestions will be appreciated. Thanks.
====UPDATE====
When I fiddled around with maven, I found that I am able to access the dependencies from public repository, but not from one specific repository (only one so far I am aware of). Can this be because of some reason? I suspect some wrong matter of migration, is it the proper way of migrating from one server to another?
Also, all the proxy repositories are having the status as In service-Remote automatically blocked and unavailable. Is this related to my problem somehow?
===Settings.xml===
<settings>
<localRepository>${env.TEST_HOME}\maven.repository</localRepository>
<proxies>
<proxy>
<id>Compproxy</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>proxy.abc.com</host>
<port>81</port>
<nonProxyHosts>*.abc.com|rick*</nonProxyHosts>
</proxy>
</proxies>
<servers>
<server>
<id>MyRep</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central mirror</id>
<url>http://rick1.abc.com:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>opensymphony mirror</id>
<url>http://rick1.abc.com:8081/nexus/content/groups/public</url>
<mirrorOf>opensymphony</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>actProf</id>
<repositories>
<repository>
<id>public</id>
<url>http://rick1:8081/nexus/content/groups/public</url>
</repository>
<repository>
<id>MyRep</id>
<url>http://rick1:8081/nexus/content/repositories/MyRep</url>
</repository>
</repositories>
<properties>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>actProf</activeProfile>
</activeProfiles>
</settings>
===pom.xml===
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.test</groupId>
<artifactId>testgui_start</artifactId>
<packaging>pom</packaging>
<version>1</version>
<name>Start POM Test GUI</name>
<url>www.abc.com</url>
<build>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.abc.test</groupId>
<artifactId>testgui</artifactId>
<version>${version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
One thing you will have to do is add all the repositories you create to the public group so they become available to Maven, provided you are using the standard settings.xml that just references the public group.
Further more I would stop and restart the server and have a close look at the log and report back with more info. It might be set up to listen on specific ports and such. Also keep in mind that the startup scripts changed when we moved to 2.0 so you will have to replace the old ones that you put e.g. in /etc/init.d/.

In Maven how do I copy files using the wagon plugin?

Summary: How do I copy some generated files into a webserver (eg IIS or Apache) directory using Maven?
Details:
I have a working application that builds in Maven. I've managed to get it building using the webstart-maven-plugin which produces all the needed files (.jar and .jnlp) in a directory target/jnlp. It also creates a zip file with them all in at target/foo-1.0.zip.
At the moment the webstart plugin does not have a deploy goal - the request for it has ended up on the FAQ (question 3). It may be implemented in future, but the suggestion for the time being is to use wagon-maven-plugin.
I've never used Wagon. To start with I'd like to just copy the files to a local directory served up by a webserver. Later I'd like to copy them remotely, probably using ftp. Can someone give an example to what I need to add to the pom.xml to get the local copy working (and hopefully an ftp example too?). I can't find it in the documentation. From reading I think I might also need the Wagon Maven File Provider but as this seems to have almost no documentation I'm not sure.
Wagon providers are only there to provide additional network protocol supports (such as FTP).
If you want to copy file to a webserver (local or distant) you can use Maven upload plugin :
...
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-upload-plugin</artifactId>
</plugin>
...
In parent pom :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-upload-plugin</artifactId>
<version>1.1</version>
<configuration>
<resourceSrc>
${project.build.directory}/${project.build.finalName}.${project.packaging}
</resourceSrc>
<resourceDest>${jboss.deployDir}</resourceDest>
<serverId>${jboss.host}</serverId>
<url>${jboss.deployUrl}</url>
</configuration>
</plugin>
And to configure parameters in a smart way, I use maven profiles (in parent pom) :
<profiles>
<!-- local deployment -->
<profile>
<id>developpement</id>
<properties>
<jboss.host>localhost</jboss.host>
<jboss.deployDir>appli/jboss-4.0.4.GA/server/default/deploy/</jboss.deployDir>
<jboss.deployUrl>file://C:/</jboss.deployUrl>
</properties>
</profile>
<!-- distant deployment -->
<profile>
<id>validation</id>
<properties>
<jboss.host>ENV_val</jboss.host>
<jboss.deployDir>/home/envval/jboss/server/default/deploy/</jboss.deployDir>
<jboss.deployUrl>scp://PROJECT_LAN_HOST</jboss.deployUrl>
</properties>
</profile>
</profiles>
I've created an "ant launcher", to use it by clicking under Eclipse ant view :
<target name="copy war to JBoss local" description="Copy war to local JBoss">
<maven goal="upload:upload" options="-Pdeveloppement" />
</target>
But you can simply run it on a command line :
mvn upload:upload -Pdeveloppement
EDIT : By the way, for distant deployment, you may need a login password for scp to work. You have to add them to you Maven settings.xml file :
<settings>
...
<servers>
<server>
<id>ENV_val</id>
<username>login</username>
<password>password</password>
</server>
</servers>
...
</settings>
EDIT: You'll need to add the Atlassian repository:
<pluginRepositories>
<pluginRepository>
<id>Atlassian</id>
<url>https://maven.atlassian.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
EDIT: depending upong the remote protocol you'll have to add wagon extensions, see Uploading a directory using sftp with Maven
In the end I didn't use the Maven upload plugin - it seemed a bit limited and not part of the main maven distribution. I used the maven wagon plugin as suggested. Here is the simplest possible pom that I could make that worked. Hopefully others will find it useful, as I couldn't find anything similar easily.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<configuration>
<fromDir>${project.build.directory}/jnlp</fromDir>
<includes>*</includes>
<url>file://c:/inetpub/wwwroot</url>
<toDir>jnlp</toDir>
</configuration>
</plugin>
For remote distributions, you just change the URL type, and possibly add wagon extensions as necessary.

Resources