Deploying AEM projects using Maven - maven

We are new to Adobe and going to start working with it. Our Build Tool is maven, CI tool- Jenkins. As we are using Maven as a build tool. How to deploy our artifacts to jetty web server?
In short, Can we deploy artifacts of adobe project using maven? or do we need to have plugins for jenkins to deploy artifacts to different environment. I have came across
Maven-jetty and cargo plugin for deployments using maven to jetty webserver.

If you want to deploy your project with Maven I suggest that you use the content-package-maven-plugin. You can read more about the details in Adobes official documentation. The basic principal is the following:
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.5.24</version>
<configuration>
<userId>admin</userId>
<password>admin</password>
<targetURL>http://localhost:4502/crx/packmgr/service.jsp</targetURL>
</configuration>
</plugin>
This is a simple example that would deploy to a default AEM installation on your local machine (or same machine as mvn runs).
If you are running your build on Jenkins you might want to consider not using Maven to deploy your artifacts. Usually, you have multiple AEM instances running to which you want to deploy your content packages: "author" and "publish".
For the builds running on Jenkins I would suggest deploying your artifacts using curl. I wrote an answer about uploading and installing content packages using curl on Stack Overflow: How to install large (content) packages in AEM.

I would strongly suggest you to use the Aem maven archetype to create your project. It will come with the default settings, POM entries so that you can change your configuration to deploy it to the required environments.
Here is the link -
https://github.com/Adobe-Marketing-Cloud/aem-project-archetype

Related

What is the difference between deploying an artifact into Artifactory with 'mvn deploy' command and with Artifactory UI?

I usually use mvn versions:use-latest-versions command to update my dependencies to the latest ones which other teams have been deployed to our free Jfrog's Artifactory server on our local address : http://192.168.100.243:8082/artifactory/X_Douran/.
My problem is when I deploy an artifact (a jar file) with Artifactory UI or with curl (using Jfrog's Rest Api), the command mvn versions:use-latest-versions doesn't work correctly and do not update my pom but when I run mvn clean deploy on my source code of my dependent project then running mvn versions:use-latest-versions on my final project it works correctly and do update my dependency in my pom.
So I want to know what is the different between deploying via Artifactory UI and deploying via mvn clean deploy ?
You always need to deploy the POM along the JAR, otherwise Maven will not work correctly with these dependencies. Furthermore, you need to make sure that the metadata files are updated. I am not sure that Artifactory does this if you deploy using curl or the UI.
Deploying your own JARs regularly through the UI is not recommended. You should build them on a build server (like Jenkins) and then automatically deploy them to Artifactory.
Changing JAR files "by hand" should be forbidden.

BOM for Maven plugins

I'm trying to create a Docker image for Maven that will have the default standard Maven plugins already downloaded.
Is there any Maven BOM that contains or mock pom all the standard maven plugins?
A Maven install is little more than a bootstrap. Most of Maven's functionality is downloaded as a plugin and cached on the first Maven run.
One idea is that you could run the maven command from within the Dockerfile when building your image.
Possibly a more flexible solution would be to run a second Docker container, using Nexus (or similar repo manager) to cache downloaded dependencies:
How to dockerize maven project? and how many ways to accomplish it?

What is the purpose of tomcat-maven-plugin?

I'm having some difficulty understanding the purpose of this plugin. Is it to modify the settings in Tomcat during the build?
I am deploying to tomcat using maven, without the plugin and it seems to work fine. Not sure if I am missing something
Cheers
Maven Tomcat plugin basically just bootstraps an embedded Tomcat container for you. Saves you the trouble of configuring an external Tomcat instance for development purposes. It can also auto-start this Tomcat instance during the build and run integration tests on it, stopping it afterwards.
If you already have a functioning workflow that you're comfortable with, no need to introduce the plugin, but it's pretty easy to configure, can run multiple web apps, can run unassembled applications etc so it's convenient to have for local development.
An even more light-weight alternative would be the Jetty plugin which starts an embedded Jetty server instead.
Maven is actually a plugin execution framework where every task is actually done by plugins.
Maven Plugins are generally used to :
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
A plugin generally provides a set of goals and which can be executed using following syntax:
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running following command
mvn compiler:compile
for more information go to http://www.tutorialspoint.com/maven/maven_plugins.htm
so pulgins is used to execute goals.
suppose if you don't include plugin that is required in your execution environment then it will throw an error like
A required class is missing: Lorg/apache/maven/plugin/BuildPluginManager;
so by adding appropriate plugin in pom.xml it will resolve the dependencies and execute the goal succesfully.
to remove above error just add the following plugins :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
</plugin>
Maven is a framework used to build JAVA applications, it provides the following
Directory Structure
Configuration Files
Build Settings
It helps in easy and structured development, primarily used for REST API Calls.
Applications built on Maven Framework, would require the same to be deployed
Its better that you get the plugin installed, since on a long run you never know what dependency may go missing
-If this helps, Mark as Answer

Maven jetty or tomcat plugin with hot deploy option including dependencies

I have a maven project with root module called "sample" and two child modules in their own directories "sample-services" and "sample-web". "sample-web" is a war module which depends on "sample-services"
I want to be able to run my server from maven (it could be jetty, tomcat, or any lightweight server) and debug my code without using eclipse or intellij idea j2ee integration (for example in Intellij Idea community edition or other IDE that supports remote debugger) and just by adding a remote debugger.
I could start my app with "jetty:run" and attach the debugger but the problem is that when I change my code in "sample-services" it doesn't pick it up unless I run "mvn install" on that module separately and restart the server.
Is there a better way to be able to debug the app and have the server redeploy the code changes without having to restart the server?
I know eclipse can do this for a maven project. It will detect the changes in dependent project and upload them to the server.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.3.v20130506</version>
</plugin>
EDIT:
I ended up using tomcat maven plugin for now:
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
/
true
in your pom.xml and run in the command line: mvn tomcat7:run
Downside is that this will reload the whole app upon each change instead of hot-deploy.
So now I am looking for a hot deploy alternative.

Can Jenkins issue a "maven jboss-as:deploy" on my project?

I am trying to use Jenkins and Selenium for CI with my Spring Project that I will be running in AS7.
I would like to know if I can get Jenkins to issue a "maven jboss-as:deploy" command line on my project to deploy it to my AS7 server.
Can someone please let me know if this can be done..
No need to involve Jenkins here. Just add the jboss-as:deploy plugin to your pom.xml, bound to the pre-integration-test phase of your build. Then when you run mvn install (either locally or on Jenkins), your war will be deployed to the AS7 server.

Resources