Maven deploy to remote server - maven

I want to deploy on Amazon EC2.
But I can't deploy.. i need some help.
I use maven project & jetty component.
Here is my code.
pom.xml
<dependencies>
...
</dependencies>
<build>
<finalName>MY_PROJ</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-beta-6</version>
</extension>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
<distributionManagement>
<site>
<id>EC2</id>
<url>scpexe://ec2-XX-XX-XX-XX.compute-1.amazonaws.com:8080/www</url>
</site>
<repository>
<id>EC2</id>
<url>sftp://ec2-XX-XX-XX-XX.compute-1.amazonaws.com:8080/www</url>
</repository>
</distributionManagement>
setting.xml
<server>
<id>EC2</id>
<username>ubuntu</username>
<privateKey>c:\MY_KEY.pem</privateKey>
<passphrase></passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
And, they have an error.
situation 1. run (mvn) site-deploy
Failed to execute goal
org.apache.maven.plugins:maven-site-plugin:3.0:deploy (default-deploy)
on project sabo_proj_mvc: Error uploading site: Error performing
commands for file transfer: Exit code 1 - A 'ssh' is not an internal
or external command, operable program, or Batch file.
situation 2. run (mvn) deploy
Failed to execute goal org.apache.maven.plugins:maven-deploy-
plugin:2.7:deploy (default-deploy) on project MY_PROJ: Failed to
retrieve remote metadata
com.XXX:MY_PROJ:0.0.1-SNAPSHOT/maven-metadata.xml: Could not transfer
metadata com.XXX:my_proj:0.0.1-SNAPSHOT/maven-metadata.xml from/to EC2
(sftp://ec2-XX-XX-XX-XX.compute-1.amazonaws.com:8080/www): Cannot
connect. Reason: Session.connect: java.net.ConnectException:
Connection refused: connect
help me plz
ps. Refer to this documentation => http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ssh-external.html

In your both situation, reason is clearly identified by maven.
A 'ssh' is not an internal or external command, operable program, or Batch file.
Do you have ssh command? is it included in your $PATH?
Cannot connect. Reason: Session.connect: java.net.ConnectException: Connection refused: connect
This could be due to firewall restrictions, maybe remote host doesnt allow connection from your host. Verify if you are able to establish ssh connection from your host to remote

Related

Maven tries to deploy to malformed url when using url instead of ip

I have set up a local Reposilite repository on 192.168.0.1 and have set up a redirect for it using mvn.example.com (both IP and url are different)
My pom.xml file looks like this:
<project>
...
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0</version>
...
<distributionManagement>
<repository>
<id>my-repository</id>
<url>http://192.168.0.1:80/releases</url>
</repository>
</distributionManagement>
...
</project>
And it works fine. It deploys to address http://192.168.0.1:80/releases/group/artifact/1.0.0/artifact-1.0.0.jar as it should
However when I change the url to <url>http://mvn.example.com/releases</url> it then tries to deploy to http://mvn.example.comreleases/group/artifact/1.0.0/artifact-1.0.0.jar. The resulting pom.xml looks like this:
<project>
...
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0</version>
...
<distributionManagement>
<repository>
<id>my-repository</id>
<url>http://mvn.example.com/releases</url>
</repository>
</distributionManagement>
...
</project>
Which obviously fails as there is no / symbol between com and releases. The url http://mvn.example.com/releases/group/artifact/1.0.0/artifact-1.0.0.jar (with the missing / added) when requested from Firefox works.
The full error looks like this:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project artifact: Failed to deploy artifacts: Could not transfer artifact group:artifact:jar:1.0.0 from/to my-repository (http://mvn.example.com/releases): Transfer failed for https://mvn.example.comreleases/group/artifact/1.0.0/artifact-1.0.0.jar: Unknown host mvn.example.comreleases: Name or service not known -> [Help 1]
I'm using IntelliJ and the command line argument for deployment is deploy -f pom.xml

Unable to deploy using fabric8:deploy maven plug-in

I'm trying to deploy a simple Camel route to my local instanct of JBoss Fuse 6.2.1 server.
I'm trying to use fabric8:deploy maven plug-in.
I created fabric using fabrc:create.
In settings.xml, added fabric server.
<server>
<username>admin</username>
<password>admin</password>
<id>fabric8.upload.repo</id>
</server>
In pom.xml, added fabric8:deploy maven plugin.
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>1.2.0.redhat-621084</version>
<configuration>
<profile>sampleprofile</profile>
</configuration>
</plugin>
Then, I run
mvn fabric8:deploy -Dfabric8.jolokiaUrl=http://localhost:8181/jolokia -DskipTests -X
I'm getting below error.
Caused by: org.apache.http.NoHttpResponseException: localhost:8181 failed to respond
at org.apache.http.impl.io.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:133)
at org.apache.http.impl.io.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:54)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.jolokia.client.J4pClient.execute(J4pClient.java:190)
... 25 more
Any idea where is the problem? Thanks for your help in advance.

Releasing to Maven Central

I was added as a developer to the Maven project and now I need to make a release.
I've added nexus-staging-maven-plugin to pom.xml file.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
Also I've added distributionManagement to pom.xml
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
I've placed my credentials to ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>ossrh</id>
<username>divanov-oss.sonatype.org-account</username>
<password>divanov-oss.sonatype.org-password</password>
</server>
</servers>
</settings>
I also tried to create and use "Access User Token" on oss.sonatype.org
as my credentials.
Now I'm executing to deploy release into maven central.
mvn clean deploy
which ends up in the error:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.3:deploy
(injected-nexus-deploy) on project project: Failed to deploy artifacts:
Could not transfer artifact
project:jar:4.4.0-20141228.104011-1 from/to ossrh
(https://oss.sonatype.org/content/repositories/snapshots): Access denied to:
https://oss.sonatype.org/content/repositories/snapshots/project/project/4.4.0-SNAPSHOT/project-4.4.0-20141228.104011-1.jar,
ReasonPhrase: Forbidden. -> [Help 1]
or
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "329a0bc2b7ce06"
[ERROR] Remote staging finished with a failure: 403 - Forbidden
[ERROR]
[ERROR] Possible causes of 403 Forbidden:
[ERROR] * you have no permissions to stage against profile with ID "329a0bc2b7ce06"? Get to Nexus admin...
How can I check my access rights within Maven project I'm trying to release?
Your credentials are likely fine, you'd be getting a 401 error if they weren't. You're getting 403 (forbidden). This means the credentials were accepted, but you don't have permission to publish the artifacts. The most common cause of this is that you are using a different Maven group ID than the one assigned to you. File an issue at https://issues.sonatype.org in the "Community Support - Open Source Project Repository Hosting" and we'll get this worked out.
The credentials that you need to use shouldn't be of Sonatype JIRA, but of oss.sonatype.org. You need to register there separately.
[Update] The question was changed, so this answer is not relevant anymore. I'll keep it, since it's a common mistake.

Could not connect to remote://localhost:9999. The connection timed out Jboss 7.1.1 Final

I am deploying builds to local and remote Jboss AS 7.1.1 Final at port 9999. Maven uses jboss plugin 'jboss-as-maven-plugin:7.1.1.Final' to manage builds to servers. I have confirmed that server is up and running and port is accessible at 9999. But "many times" build fails with following error for both local and remote Jboss. Jboss ic configured in Standalone mode single node cluster.
Stranglely build doesn't fail every time but most of the time. Not sure if we need to upgrade Maven plugin to higher version.
[INFO] o.h.m.e.h.MavenExecutionResultHandler - Build failed with
exception(s) [INFO] o.h.m.e.h.MavenExecutionResultHandler - [1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to
execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.1.1.Final:undeploy
(default-cli) on project Test: Error executing UNDEPLOY [DEBUG]
Closing connection to remote [ERROR] Failed to execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.1.1.Final:undeploy
(default-cli) on project Test: Error executing UNDEPLOY:
java.net.ConnectException: JBAS012144: Could not connect to
remote://localhost:9999. The connection timed out -> [Help 1]
UPDATE
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.1.Final</version>
<configuration>
<filename>${project.build.finalName}.jar</filename>
<username>${userName}</username>
<password>${password}</password>
</configuration>
</plugin>
I am now using latest version of Maven plug-in but it seems that connection timeout error is more frequent now. I am starting to think if Jboss behaves differently when trying to make too many remote deployment with different sub projects of the application. I am having 21 sub projects being deployed from a master POM. Sample configuration is as follows
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.master</groupId>
<artifactId>master</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Master</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>module4</module>
<module>module5</module>
<module>module6</module>
<module>module7</module>
<module>module8</module>
<module>module9</module>
<module>module10</module>
<module>module11</module>
<module>module12</module>
<module>module13</module>
</modules>
First, check plugin configuration.
For example:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.9.Final</version>
<inherited>true</inherited>
<configuration>
<hostname>${jboss.hostname}</hostname>
<port>${jboss.port}</port>
<username>${jboss.user}</username>
<password>${jboss.pass}</password>
<timeout>30000</timeout>
</configuration>
</plugin>
If hostname, port number(default 9999), username and password are ok, you can try increasing "timeout" (default is 5000ms, you can try with 30000ms).
It worked for me.
4 Possible Solutions to Question
Remove your Local Cache settings which will be your local m2 repo Or Point to new m2 repo from your maven settings.xml file.
Try to connect to your local nexus/archiva (if any other) using relevant/appropriate credentials.It is only your Maven Plugin causing this problem.
Try to use the latest JBoss Deploy Plugin available in this link.
Alternatively check your windows/Linux firewall settings have been enabled or it.

Unable to deploy to Tomcat7 from cargo

I'm trying to deploy to a remote Tomcat7 with Cargo from Maven over https.
I've set up manager-script role and I've succeeded so far as to have been able to undeploy an app remotely.
What I have looks like this:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.uri>https://xxx/manager/text</cargo.remote.uri>
<cargo.remote.username>${tomcat.username}</cargo.remote.username>
<cargo.remote.password>${tomcat.password}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>mycomp</groupId>
<artifactId>myartifact</artifactId>
<type>war</type>
<properties>
<context>/</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
Well, I know the credentials and everything is setup correctly, and I have used the new /text interface and I have been able to undeploy an existing app. But when trying to run deploy:
mvn cargo:deployer-deploy -e
I get an error with root cause:
Caused by: java.io.IOException: Error writing request body to server
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(HttpURLConnection.java:2809)
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:2792)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.pipe(TomcatManager.java:605)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:501)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:569)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:273)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:256)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:240)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:101)
... 25 more
I get it quite immediately so it can't be a timeout.
Can the file be to large? It's a 60 MB war. I made sure my nginx allows bigger:
client_max_body_size 200M;
I also added multipart config to the text manager in the manager webapps web.xml like this:
servlet>
Manager
org.apache.catalina.manager.ManagerServlet
debug
2
<multipart-config>
<max-file-size>209715200</max-file-size>
<max-request-size>209715200</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
http://nexnet.wordpress.com/2011/04/27/large-war-file-cannot-be-deployed-in-tomcat-7/
I love Maven in many ways, but the error reporting is really terrible. Any help highly appreciated.
I was bitten by this error recently, when I tried to cargo:deploy an artifact. Usually we stop, clean and start the webapps directory before deploying, but this time I noticed that one artifact was not removed.
After switching to cargo:redeploy the error was solved.
I ran into this same error message when deploying to a tomcat 8 server using the ant deploy task. The issue in my case was that I was running out of space on the server. Checking tomcat's manager log is what clued me in:
10-Jul-2014 10:15:38.065 INFO [http-nio-8080-exec-2] org.apache.catalina.core.ApplicationContext.log Manager: deploy: Deploying web application '/abc_beta'
10-Jul-2014 10:15:38.065 INFO [http-nio-8080-exec-2] org.apache.catalina.core.ApplicationContext.log Manager: Uploading WAR file to /usr/share/apache-tomcat-8.0.9/webapps/abc_beta.war
10-Jul-2014 10:15:57.962 SEVERE [http-nio-8080-exec-2] org.apache.catalina.core.ApplicationContext.log Manager: managerServlet.check[/abc_beta]
java.io.IOException: No space left on device
... stacktrace ...
I don't remember if or how I solved this, but as rascio has the same problem, I'll post a an idea. Maybe it's the wagon-extension for ssl that's needed:
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.2</version>
</extension>
</extensions>
Wild guess though. I think you didn't need it before Maven 3.0.
Another reason for this exception that we stumbled upon suddenly on monday, when deployment jobs on our Jenkins instance using the cargo plugin plugin stopped working. Not all of them, but some. The main difference was a a custom settings.xml in the jobs for a Nexus repository to download deployables from.
The successful deployment jobs had it configured like described in https://support.sonatype.com/entries/20943003-configure-maven-to-download-from-nexus, the failed ones were missing the repository and pluginRepository
I'm still not sure why the behavior changed at one point. Any tipps?

Resources