How does maven jetty package a war? - maven

I am running an open source piece of software (https://github.com/att/XACML) and the documentation says to use maven jetty to run the application. This works fine.
However, I am trying to run it without maven as a dependency, so I am thinking of using the generated war and deploying it with jetty. However, this approach gives me errors specific to the war (can not instantiate null etc.) that do not sure up when running maven jetty.
So my question is: how does maven jetty package the war? Is there anything it does at runtime that would make it different than just trying to deploy the war on its own? What is the difference between using maven jetty and using something like jetty runner with the war generated from maven clean install?

Jetty does not package a war.
Maven does, and you need ...
Your project's pom.xml should be declared as <packaging>war</packaging>
You have a src/main/webapp directory.
You have maven execute the package phase.
When you use something like mvn jetty:run-war the first thing that happens is the package phase executes, THEN the jetty:run-war goal executes.
See: JettyRunWarMojo.java
#Mojo(name = "run-war",
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
#Execute(phase = LifecyclePhase.PACKAGE)
public class JettyRunWarMojo extends AbstractMojo
Jetty is not doing the packaging of war, Maven and it's default package phase is (and the behaviors here are determined by the standard maven lifecycle defined by your <packaging>war</packaging>)
See: https://maven.apache.org/ref/3.2.2/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging

Related

Use of spring-boot-maven-plugin

While creating a spring boot project I define property in pom.xml as <packaging>war</packaging> with which I can create a war and thereafter deploy the war into server maybe tomcat or WAS.
But I came across a plugin named spring-boot-maven-plugin whose documentation states that it's use is to package executable jar or war archives and run an application in-place.
My query is why do we need this at all ?
If my packaging can tell me what to create and then can deploy it to run, what is the used of this plugin.
I am trying to understand a new project so wanted to be sure that every line makes sense
The maven plugin will create an "executable" archive. In the case of the war packaging, you would be able to execute your app with java -jar my-app.war. If you intend to deploy your Spring Boot application in an existing Servlet container, then this plugin is, indeed, not necessary.
The maven plugin does more things like running your app from the shell or creating build information.
Check the documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven, letting you package executable jar or war archives and run an application “in-place”.
Refer this - https://www.javaguides.net/2019/02/use-of-spring-boot-maven-plugin-with.html

Building/deploying a EJB .jar with its dependencies

I am new to Java EE. I use Maven, Eclipse and jBoss/WildFly.
I have a war project. When I build the project all its dependencies are packaged inside the war file in WEB-INF/lib.
Now I am trying to create a ejb project (I have <packaging>ejb</packaging> in the pom.xml). I want to deploy it as a separate project (not as a part of the war). When I build the ejb project Maven does not package any dependencies in the jar.
How can I package/deploy a ejb .jar with its dependencies?
UPDATE: I'd like to avoid packaging EJBs in an .ear if it is possible. (I do not want to create one more Maven project).
The best solution is package your project as ear. But if don't want use ear, maven assembly plugin can help you to package all needed jars in one file. This solution is only for "proof of concept" variant, and cannot be used in production mode, by licences limitation for example.

Maven JBOSS application deployment

I followed this tutorial http://www.mastertheboss.com/jboss-maven/jboss-maven-example-building-a-java-ee-6-application/ in order to have a simple web application to better understand Java EE and JBOSS. I set up the example project (by archetype) and compiled it.
However, I am stuck after running mvn compile. I want to deploy my application as a war file to my JBOSS webroot directory (in my case /usr/share/jboss-as/standalone/deployments/).
I think mvn package and mvn install must be executed. Where can I specify that I want a war file and that it should be copied to my deployment location on JBOSS?
Obviously, I can use the jboss maven plugin http://docs.jboss.org/jbossas/7/plugins/maven/latest/, which is addressed via console
jboss-as:deploy
Configuration is read from the POM file.

maven does not copy dependencies

I have Dynamic Web Application project in eclipse that was converted to maven project.
Problem is that all dependencies are copied to:
<project>/target/<project>-SNAPSHOT/WEB-INF/lib
not <project>/WebContent/WEB-INF/lib
so when I run application from eclipse, there are no libs from maven and I get some errors.
I assume that application started from eclipse i.e on tomcat server gets it source from <project>/WebContent/WEB-INF/lib.
You should use m2e (Maven Plugin for Eclipse). It automatically adds Maven dependencies to the classpath, so you don´t need them in /WEB-INF/lib while running from Eclipse.

Maven Jetty Run from Jar

Here is want I want to do. I created a maven project and configured the jetty plugin for it in eclipse...
So from Eclipse if I do run and set the maven goal there to be jetty:run it runs my project in jetty on the port specified in web.xml. Now I want to build the jar file and when I do java -jar myapp.jar it will automatically call jetty:run.
How can I do this?
If you want to package your application so that you can hand it to someone and have them run it as a standalone application without having to go through deploying a war file into a web container, then that is a different concern from doing mvn jetty:run at development time, I will call that deployment time to avoid any confusion
At deployment time, we can't assume there will be maven on the machine, thus no mvn jetty:run, and even if there was, this would not work, unless we deliver the source code to run the build as in the development environment!
A standalone web application can be packaged by bundling the jetty jars in the application war along with a Main class to start jetty programmatically, and get it to run the application war. This relies on the fact that the file and directory structure of the WAR and JAR are different, and thus there is no significant overlap between the two, which is what makes this workaround possible, and it also leaves the option of deploying the war file in a web container possible
There is a maven plugin that embeds winstone which is another lightweight servlet container
For jetty, you may start by reading Embedded Jetty 7 webapp executable with Maven

Resources