I am trying to create a runnale openliberty server as part of my release process. I have a a multi module maven project with a submodule dedicated to packaging the server as a runnable. When I do a mvn clean package a lovely executable jar is produced which bundles one of the other submodules (war). The problem I am facing is when I do a maven deploy to our asset repo the packaged server is being uploaded as a zip file rather than a jar file. Does anyone know how to get the deploy plugin to upload the jar?
Here is a sample pom file
<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>
<parent>
<groupId>au.com.xxxx.xxxx</groupId>
<artifactId>xxx-backend-parent</artifactId>
<version>0.0.16-SNAPSHOT</version>
</parent>
<artifactId>xxxx-openliberty-server</artifactId>
<packaging>liberty-assembly</packaging>
<name>fusion-openliberty-server</name>
<description>Runnable Jar containing xxxxand the OpenLiberty applictaion server</description>
<dependencies>
<!-- Package xxxx-application.war with server assembly -->
<dependency>
<groupId>au.com.xxx.xxx</groupId>
<artifactId>xxxx-application</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Enable liberty-maven-plugin -->
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>2.6.1</version>
<extensions>true</extensions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-javaee8</artifactId>
<version>18.0.0.3</version>
<type>zip</type>
</assemblyArtifact>
<include>runnable</include>
<serverName>xxx</serverName>
<appsDirectory>apps</appsDirectory>
<serverEnv>${basedir}/src/main/resources/server.env</serverEnv>
<configFile>${basedir}/src/main/resources/server.xml</configFile>
<jvmOptionsFile>${basedir}/src/main/resources/jvm.options</jvmOptionsFile>
<bootstrapProperties>
<app.context.root>xxx-app</app.context.root>
<default.http.port>5000</default.http.port>
<default.https.port>5443</default.https.port>
</bootstrapProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
I don't have an answer to your question but an explanation why this happens. Every packaging type (jar, war, liberty-assembly) defines a fixed extension for the artifact(s) it creates. The liberty-assembly types defines zip as it extension. This extension is used by the maven-install-plugin and maven-deploy-plugin regardless how the local file is names. I did quite some code digging but couldn't find a way to change this. It's probably sth. that only liberty-maven-plugin can change/fix.
I want to package one EAR that will be deployed on GlassFish Server Open Source Edition.
Here are the relevant parts of the pom.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<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>
....
<packaging>ear</packaging>
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>/lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
I usually run mvn compile and mvn package in the command terminal. The resulting EAR has the following structure.
EAR/lib/*.jar
EAR/META-INF/application.xml
EAR/META-INF/META-INF.MF
EAR/META-INF/maven/...
The application.xml is
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>test-app</display-name>
<library-directory>/lib</library-directory>
</application>
If I try to run asadmin deploy test-app.ear to deploy the EAR to GlassFish I get this error.
remote failure: Error occurred during deployment: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 22; Deployment descriptor file META-INF/application.xml in archive ....
Here I rename application.xml to glassfish-application.xml and change its content to
<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Java EE Application 6.0//EN"
"http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
<unique-id>67488732739338240</unique-id>
</glassfish-application>
If I rerun asadmin deploy test-app.ear GlassFish recognizes the deployment descriptor but throws the next error that says Application [test-app] contains no valid components.
Here I move all jars from EAR/lib/*.jar to EAR/META-INF/lib/*.jar.
If I now rerun asadmin deploy test-app.ear GlassFish recognizes the EAR as valid and deploys it.
Since I dont want to manually change the EAR every time. How can I configure Maven to
1. Output a valid application.xml or glassfish-application.xml
2. Copy the dependencies not to EAR/lib/ but to EAR/META-INF/lib (if it is really necessary)
Thanks in advance.
How can I configure Maven to
Output a valid application.xml or glassfish-application.xml
Copy the dependencies not to EAR/lib/ but to EAR/META-INF/lib (if it is really necessary)
application.xml can be autogenerated by maven-ejb-plugin and for the simple test I would leave it up to plugin
for dependencies copying - it depends what you package in your ear (can be war/jar/...) but in general, it's a good idea, to let maven do it. For the purpose you miss in your pom.xml sections that would refer to modules (war/jar/...) you want to be included in there
moreover I don't see a reason for non-standard libs folder you specified with: <library-directory>
So I'd go for config like the sample present here.
To include the relevant sections in answer:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<modules>
<webModule>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<bundleFileName>myWarNameInTheEar.war</bundleFileName>
<contextRoot>/myWarConext</contextRoot>
</webModule>
<ejbModule>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<bundleFileName>myEjbNameInTheEar.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>My Ear Name displayed in the App Server</displayName>
<generateApplicationXml>true</generateApplicationXml>
</configuration>
</plugin>
</plugins>
</build>
<!-- Define the versions of your ear components here -->
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myWar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myEjb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
Please note you need to specify dependencies - for modules, but include those in modules section as well, to have them packaged.
Feel free to ask in case of any further questions.
I am following this Contract first using CXF tutorial and while the resulting pom.xml generates sources and even completes build successfully, it fails to create a WAR file.
Instead, it creates a JAR file.
My understanding is that the part in the pom.xml that's responsible for creating the WAR is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>D:/path/to/profile/autodeploy</outputDirectory>
</configuration>
</plugin>
I don't see any <goal> or <execution> element there (unlike in the build-helper-maven-plugin one), but I also understand that with this plugin this is implied as even the official usage page demonstrates:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
So... what am I missing?
What could possibly explain a maven-war-plugin that behaves in unexpected way like this and produces a JAR instead of a WAR by default?
Is there a way to force it to produce a WAR?
packaging should be as below.
<packaging>war</packaging>
if it won't help then try binding your plug-in configuration with a lifecycle phase.
in your project definition , please check if packaging is missing or not , it should be some thing like this .
<groupId>some.groupid</groupId>
<artifactId>My Web Application</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<description>My First Web Application</description>
By default maven war plugin binds to package phase of the lifecycle ,so its important that we should mention the type of packaging we want once the build is done.
I would like to suggest to have a look at the Maven specs for war plugin.
I am getting the following error:
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
I have got web.xml in right place which is projectname\src\main\webapp\WEB-INF\web.xml
What could be causing this?
It would be helpful if you can provide a code snippet of your maven-war-plugin.
Looks like the web.xml is at right place, still you can try and give the location explicitly
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
This solution works for me (I was using 2.2 before). Also, I am using Java Based Configuration for Servlet 3.0 and no need to have web.xml file.
It works perfectly for me too.
<project>
.....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is because you have not included web.xml in your web project and trying to build war using maven. To resolve this error, you need to set the failOnMissingWebXml to false in pom.xml file.
For example:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Please see the blog for more details: https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
If you are migrating from XML-based to Java-based configuration and you have removed the need for web.xml by implementing WebApplicationInitializer, simply remove the requirement for the web.xml file to be present.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
...
</configuration>
The value of my webXml tag needed to look like this in order to work:
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
I had the exact same problem and i solved it like this :
Make a new folder named WEB-INF under src/main/webbapp then
Right Click on your Project -> Java EE Tools -> Generate Deployment Descriptor Stub
This should generate your web.xml
I hope this helps by solving your problem :D
It does look like you have web.xml in the right location, but even so, this error is often caused by the directory structure not matching what Maven expects to see. For example, if you start out with an Eclipse webapp that you are trying to build with Maven.
If that is the issue, a quick fix is to create a
src/main/java and a
src/main/webapp directory (and other directories if you need them) and just move your files.
Here is an overview of the maven directory layout:
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
🔴 failOnMissingWebXml since 2020
All other answers about might be obsolete because the default value used by the maven-war-plugin changed:
Starting with 3.0.1, this property defaults to false if the project depends on the Servlet 3.0 API or newer.
So the ONLY thing you have to do is to add
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Example:
<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>foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
As per the documentation, it says : Whether or not to fail the build if the web.xml file is missing. Set to false if you want you WAR built without a web.xml file. This may be useful if you are building an overlay that has no web.xml file.
Default value is: true.
User property is: failOnMissingWebXml.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<extensions>false</extensions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Hope it makes more clear
It worked for me too.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
This is an old question, and there are many answers, most of which will be more or less helpful; however, there is one, very important and still relevant point, which none of the answers touch (providing, instead, different hacks to make build possible), and which, I think, in no way has a less importance.. on the contrary.
According to your log message, you are using Maven, which is a Project Management tool, firmly following the conventions, over configuration principle.
When Maven builds the project:
it expects your project to have a particular directory structure, so that it knows where to expect what. This is called a Maven's Standard Directory Layout;
during the build, it creates also proper directory structure and places files into corresponding locations/directories, and this, in compliance with the Sun Microsystems Directory Structure Standard for Java EE [web] applications.
You may incorporate many things, including maven plugins, changing/reconfiguring project root directory, etc., but better and easier is to follow the default conventions over configuration, according to which, (now is the answer to your problem) there is one simple step that can make your project work: Just place your web.xml under src\main\webapp\WEB-INF\ and try to build the project with mvn package.
If you change the default project path, you must specify the location of the web.xml file, for example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<webXml>src\main\web\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
mvn-war-plugin 2.3 fixes this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
...
I have had the same error on the test server but not in local. After a few minutes, I discovered that the IDE wasn't synchronized with the pom.xml. Here is how I solve it:
Re-Generate the deployment descriptor with Eclipse
Right click on your project folder
In the contextual menu, choose "Java EE Tools" then "Generate Deployment Descriptor Stub"
It will create the web.xml.
Re-Generate the deployment descriptor with IntelliJ
Right click on your project folder
In the contextual menu, choose "Open Module Settings", then click on the + to add the web deployment descriptor.
Then your can change the path to your descriptor or the Web Ressource Directoriesand the on the right side.
Then you will get something like:
Make sure pom.xml is placed properly in Project folder. and not inside target folder or any where else.
Looks like pom.xml is not relatively aligned.
Was your folder structure altered so the file is no-longer at /src/main/webapp/WEB-INF/web.xml ?
To resolve this issue, I gave my web folder the name webapp and placed it inside the src/main. Maven seems to look for web.xml by default at /src/main/webapp/WEB-INF/web.xml. If you do this then you don't need to explicitly tell maven where web.xml is. And if you've altered your folder structure and your build recently stopped working, this could be why.
Note: This is an old post but the posted solutions don't point out why a working build would suddenly stop working.
This error occurs because you tell to Maven to pakage files to war.
<packaging>war</packaging>
Do you really need war? If not, put jar there.
Here is full code:
<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>
<version>1.0-SNAPSHOT</version>
<groupId>com.your.groupid</groupId>
<artifactId>artifactid</artifactId>
<packaging>jar</packaging>
I encountered this message while trying to package a Spring Boot project as a WAR file and deploying that WAR file in a standalone Tomcat instance.
I used Spring Intializr to generate the initial pom.xml and related artifacts.
The problem was that in that pom.xml (Spring version 2.6.+), this dependency was in place.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
I had to replace it with this one:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
And also added this dependency with scope of "provided"
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Also, of course, changed the packaging
<packaging>war</packaging>
Make sure to run mvn install before you compile your war.
There are two things to note regarding packaging.
Packaging to a war file will require you define the web.xml file in the appropriate folder as described by Catalin Ciolocoiu.
But changing the package type to jar would not need that structure and should work straight away.
while I am using sonar findbug for code review, it throws exception, claiming some classes are missing.
After some research, it's clear that the jars needed to build the project, should be included in the pom.xml for sonar's use.
to do that, sonar official web site suggesting, add dependencies,
com.opensymphony
xwork-core
2.1.6
system
${basedir}/.../xwork-core.jar
however, for me, it's always not working.
I am using windows, would anyone please enlighten me, how to configure, especially the systempath?
Here is the pom.xml, for one module of the project.
<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>DB</groupId>
<artifactId>Project1</artifactId>
<name>project1</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork-core</artifactId>
<version>2.1.6</version><!--installed into .m2 folder, local repository, then refer it-->
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep1</artifactId>
<version>1.0</version> <scope>system</scope>
<systemPath>${basedir}/lib//asn.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>build-to/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
Thanks,
Jackie
Is your project already a maven project, or are you compiling things with ant or some other tool and then trying to get sonar to run against it? Sonar Light mode can be tricky with very complex projects. If you've got a multi-module project, i'd get the simplest project working under a local copy of sonar and then work towards adding more modules.
Additionally, I would try copying the files locally to a different directory that does not step up from ${basedir}. See if that helps. So ${basedir}/lib/xwork-core.jar something like that.
Perhaps for Sonar analysis, you can have a separate task copy the needed libraries to a temp folder that can be accessed appropriately, and then remove them once the analysis is complete.
i found out the problem. The official documentation of sonar is actually wrong.
"mvn sonar:sonar" would invoke the maven sonar plugin 2.0 beta, which won't enable the dependency of library jars work. Instead, call "mvn sonar3:sonar", invoke the maven sonar plugin 2.4.1, the latest version, works.