I use cargo-maven2-plugin to deploy war files to a running remote tomcat container. Now I need to copy files to $CATALINA_HOME/myfolder. I do this using ant-run/scp/ssh.
But is it possible to do this with the cargo-maven2-plugin or does it only operate on the application/webapps level?
Try cargo with installed deployer and existing configuration
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.5</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<home>${env.CATALINA_HOME}</home>
</container>
<configuration>
<type>existing</type>
<home>${env.CATALINA_HOME}</home>
</configuration>
<deployer>
<type>installed</type>
</deployer>
</configuration>
</plugin>
My sample project works this way
$ mvn cargo:deploy
[INFO] --- cargo-maven2-plugin:1.4.5:deploy (default-cli) # sample-war ---
[INFO] [edDeployerDeployMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-tomcat:jar:1.4.5 for container tomcat7x
[INFO] [stalledLocalDeployer] Deploying [/home/mariuszs/git/sample-war/target/sample.war] to [/opt/tomcat/webapps]...
You can check full sample project for this https://github.com/mariuszs/cargo-existing-installed-sample
Some links than can help:
Local container
Existing Local Configuration
Related
I'm using the maven-deploy-plugin to deploy into Nexus an artifact generated by a task of maven-antrun-plugin at the end of my build.
The Ant task simply creates a file .sh of the assembled archive built by Maven.
I had to include maven-deploy-plugin because otherwise the .sh is not uploaded into Nexus and it's completely ignored by the lifecycle of the build.
This is the plugin configuration I've tried:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>deploy-sh</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<skip>false</skip>
<file>${project.build.directory}/${project.artifactId}-${project.version}-autoinstaller.sh</file>
<repositoryId>myrepo</repositoryId>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</configuration>
</execution>
</executions>
</plugin>
I run the Maven build with mvn clean deploy goals, but it fails with the following error:
[INFO] --- maven-deploy-plugin:3.0.0-M1:deploy-file (deploy-sh) # MyApplication ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:11 min
[INFO] Finished at: 2020-05-01T19:07:40+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file (deploy-sh) on project MyApplication: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid -> [Help 1]
The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid
Yes, this occurs because there's not the <url> tag in the section, so it's a mandatory parameter.
But why the <distributionManagement> is completely ignored? I also have a distributionManagement configured for myrepo repository, so urls are configured there.
What I have to do to make it work within the distributionManagement for snapshots and releases?
Following this answer, I found the following solution:
I have removed completely the maven-deploy-plugin
I have added <attachartifact> ant task in the maven-antrun-plugin
In this way, the file produced by the Ant run plugin is correctly deployed to Nexus, as described here:
AttachArtifact Task
This task will attatch an artifact to the current Maven project. This is can be used to install and deploy an artifact generated by the Ant tasks.
I am trying to deploy a war in a docker container based on the oracle/glassfish:5.0 image.
I am able to deploy the war through the Glassfish Administration Console and manually uploading the war file.
Nevertheless, I would like to deploy the war with maven using the cargo plugin.
The versions I am using are:
javac 9.0.1
Apache Maven 3.3.9
Maven cargo plugin 1.6.6
Docker image oracle/glassfish:5.0
The container has been built as:
docker run -ti -e ADMIN_PASSWORD=password -p 4848:4848 -p 8080:8080 -d oracle/glassfish:5.0
The configuration I have setup in the pom.xml is:
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>glassfish5x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.runtime.args>force=true</cargo.runtime.args>
<cargo.hostname>127.0.0.1</cargo.hostname>
<cargo.glassfish.admin.port>4848</cargo.glassfish.admin.port>
<cargo.glassfish.domain.name>domain1</cargo.glassfish.domain.name>
<cargo.remote.username>admin</cargo.remote.username>
<cargo.remote.password>password</cargo.remote.password>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
The error displayed is:
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-
plugin:1.6.6:deploy (default-cli) on project hello1:
Execution default-cli of goal org.codehaus.cargo:cargo-maven2-plugin:1.6.6:deploy failed:
Deployment has failed: Action failed Deploying application to target server failed;
File not found : /var/folders/b0/kd4wyk3s1rnfs_rvvbc_m2400000gn/T/cargo/19525/hello1.war -> [Help 1]
I'm moving from Eclipse to Intellij, and switching from Tomcat to Jetty in the dev environment.
My Tomcat plugin works fine, but when I start Jetty it outputs the following error:
Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.2:run (default-cli) on project projeto: Webapp source directory C:\Users\EvCash - Blue\workspace\projeto\src\main\webapp does not exist -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.2:run (default-cli) on project projeto: Webapp source directory C:\Users\EvCash - Blue\workspace\projeto\src\main\webapp does not exist
Here is my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.2</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
</connector>
</connectors>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
...
</plugins>
</build>
And the run configuration:
jetty:run -e
I tried using the jetty-runner plugin, but it requires JDK 1.8 and I must use the 1.7 version.
Any ideas? Thanks in advance
I have a maven project which builds a WAR and then packs it into a zip file which targets a specific deployment tool. I don't want to upload the WAR as it will be a waste of space.
Is it possible to build the WAR but only upload/deploy the zip in the same pom file?
Edit:
No, the "duplicate" question suggested above does not help the slightest. I have to specify <packaging>war</packaging> and even if I don't, as soon as I use the maven war plugin, it's going to make the war as part of the deployment.
And I also want the other artifacts in the build (source, tests, etc.). I just do not need the war.
Here is a suggested approach to deploy the war or the zip, depending on the need:
The default build will still provide a WAR as output
A profile is added to skip the normal Maven Deploy Plugin execution as part of the deploy phase and add a further execution (obviously not skipped) deploying only the ZIP file via the deploy-file goal, as suggested by #Michal, but not via command line (better as part of the build).
Depending on the need you can of course switch the default behavior from the profile to the default build or even get rid of the default build (just the WAR) at all.
An example:
<build>
<finalName>test-war-zip</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy-zip</id>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-zip</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<skip>false</skip>
<file>${project.build.directory}/your.file.here</file>
<repositoryId>your.id.here</repositoryId>
<url>http://something.here</url>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Note the global configuration for the Maven Deploy Plugin and its skip to true. It will effectively skip the deploy goal. A further execution will take care of the ZIP file.
With the approach above, executing the normal build, Maven will keep on deploying the generated WAR, while switching on the profile as following:
mvn clean deploy -Pdeploy-zip
Maven will skip the default execution of the Maven Deploy Plugin (its deploy goal) and execute instead the deploy-file goal during the deploy phase.
As part of the build you will then have:
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # test-war-zip ---
[INFO] Skipping artifact deployment
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-zip) # test-war-zip ---
Uploaded: http://the.repository.here (986 B at 3.9 KB/sec)
I want cargo maven plugin to start a Tomcat7 so i put into my pom:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.0</version>
<!-- minimal configuration to let adb run (mvn package org.codehaus.cargo:cargo-maven2-plugin:run) in a local tomcat -->
<configuration>
<containerId>tomcat7x</containerId>
<containerUrl>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip
</containerUrl>
<configuration>
<properties>
<cargo.servlet.port>1718</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
The Problem is if i run:
mvn package org.codehaus.cargo:cargo-maven2-plugin:run
all is working fine but if i run
mvn package org.codehaus.cargo:cargo-maven2-plugin:start
the configuration set in pom is beeing ignored:"No container defined, using a default [jetty6x, embedded] container"
you can reproduce this easily. just create an war-maven app:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webappp
Then add the code above to pom and run both commands.
So how to set ContainerId and Url properly for goal start -- Am I missing something?!
so i contacted cargo support. the configuration above works indeed only with run goal, but there is also a configuration that works with both (the cargo doc is somehow misguiding):
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.0</version>
<!-- minimal configuration to let adb run (mvn package org.codehaus.cargo:cargo-maven2-plugin:run) in a local tomcat -->
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip</url>
</zipUrlInstaller>
</container>
<configuration>
<properties>
<cargo.servlet.port>1718</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
notice the additional container and zipUrlInstaller tag instead of containerUrl.