Maven jetty or tomcat plugin with hot deploy option including dependencies - maven

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.

Related

Deploying AEM projects using 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

unable to acess the admin console of Wildfly when using wildfly-maven-plugin

I am new to Wildfly (8.0.0.Final) and maven. I used the standalone script to start WildFly server and I've added a management user called admin to be able to acess the admin interface. But when I start the wildfly server using wildfly maven plugin like this :
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.0.Final</version>
<configuration>
/configuration>
</plugin>
and trying to access the admin console I see a prompt message ""Your WildFly Application Server is running. However you have not yet added any users to be able to access the admin console.""
Any clue??? Thanks
First of all why don't you use the latest versions of a) wildlfy server: 8.2.0 and b) wildlfy maven plugin: 1.0.2.Final
Now if you want to use maven to both start the server and deploy your app then you need to tell to maven where your server is located by using -Djboss-as.home property (info taken from http://blog.arungupta.me/wildfly-maven-plugin-tech-tip-9/) or set the <jbossHome/> configuration tag.
If the property -Djboss-as.home or <jbossHome/> is not specified WildFly is downloaded and started and the application is deployed to it. You will find at the target directory of your project the newly downloaded server, in my case: mavenWildfyTest\target\wildfly-run\wildfly-8.2.0.Final
Check into the bin folder and you will find add-user.bat. If you run it you will add a user and you will be able to log in to the management console of the downloaded wildlfy server.
However, I believe, this is not what you want but instead you want to use maven plugin to deploy apps in your own Wildfly server.
In that case you have two options:
start the server beforehand by using the standalone script (bat or sh) and then use mvn wildfly:deploy or
use mvn wildfly:run with -Djboss-as.home defined, in my case: mvn wildfly:run
-Djboss-as.home=K:\app_servers\wildfly-8.1.0.Final

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

How do I deploy a maven created webapp to tomcat

So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml

Issues with classpath running Jetty via Maven

I'm using Maven to manage my build. For developer testing I use Jetty which I launch using the jetty:run goal in the Jetty Maven plugin. I should also note that I have war:exploded running in an earlier phase which builds the directory that Jetty runs against.
The problem I'm having is that the war:exploded task puts the build dependencies into WEB-INF/lib (as it should) and furthermore, Maven appears to be feeding Jetty the build classpath via the system classloader. This leads to every jar getting loaded twice which should be OK except that, sadly, the Datanucleus library throw an exception the second time it gets loaded onto the classpath.
The only solution I can think of at the moment is to create two profiles, a build profile and a developer test profile. The developer test profile would exclude all the dependencies and jetty:run would run in the developer test profile. This seems like a lot of configuration for something I think would be simple.
Does anyone know if there is a way to prevent Maven from loading the build classpath into Jetty?
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
...
The option "useTestClasspath" should have the effect you are looking for.

Resources