I'm trying to customise WAR archive generation with maven in a way that a certain client jar is at the root of a war file instead of default WEB-INF/lib directory
I used the copy goal of maven-dependency-plugin to copy this jar to location ${project.build.directory}${file.separator}${project.artifactId}-${project.version} this copies it as expected i.e. target/mywar-1.0-SNAPSHOT folder
\-target
|-mywar-1.0-SNAPSHOT
|-WEB-INF
|-lib
|-classes
|-something.jsp
|-other-jar-1.0-SNAPSHOT.jar
however, when the maven build generates a WAR archive this JAR is not included in the packaging in the root of WAR archive. How do I get the following WAR archive structure in place with maven?
\-mywar-1.0-SNAPSHOT.WAR
|-WEB-INF
|-lib
|-classes
|-something.jsp
|-other-jar-1.0-SNAPSHOT.jar
notice that this other jar should be at the same level as WEB-INF not inside it.
I would think the war plugin takes its input from the src directory, not the target directory. See the war-mojo docs.
What might help is this howto on how to add additional resources into the war file.
Related
As part of maven build, I want the war file to include a file that is located on http. Is this possible?
The folder strcuture should look something like this
META-INF
WEB-INF
ui.zip > This has to be pulled from an external resource located on web.
I have a dependency utilities.jar which has a dev.properties file in the root directory when compiled (in src/main/resources when uncompiled). The jar has a class (PropertiesUtil.java) that loads the properties with:
PropertiesUtil.class.getResourceAsStream("/dev.properties");
This jar is included as a dependency in my webapp. The webapp has its own dev.properties file in its root directory when compiled (in uncompiled form its in the src/main/resources folder).
The utilities.jar does not load its own internal dev.properties file but instead the webapp's dev.properties file.
I tried different methods like
PropertiesUtil.class.getClassLoader.getResourceAsStream("dev.properties");
without success.
I am using Gradle to compile the utilities.jar and the webapp into a war. The properties filename need to be the same because I pass in a JVM property
-Dproperty.filename=[dev|qa|prd].properties
when starting up the webapp. This system property is used to load the correct properties files for the webapp and the utilities.jar.
The utilities.jar is a separate project and packaged with gradle clean build and uploaded to an artifact server. The webapp pulls the utilities.jar from the artifact server when building the war.
I think this problem is occurring because you have two different files with exactly the same path (even though one is inside a jar) inside your classpath. It's very possible one dev.properties is getting overwritten.
I recommend changing the path of at least one of the properties files to be outside of the project root. For example, put the uncompiled dev.properties for Utilities at:
/src/main/resources/utilities/dev.properties
Then access it with:
PropertiesUtil.class.getClassLoader.getResourceAsStream("/utilities/dev.properties");
Then the two properties files won't stomp on each other anymore, and that should fix your problem.
I have quite an interesting issue. I'm running maven to compile my Servlet site into a single WAR File. This works completely fine on my local machine; and even when I change my deployment settings to use just the war file, it works fine. However, when I deploy the WAR file to the server, I'm getting 404 errors. I'm no expert with WAR files, so is there some sort of internal file that specifies the location of resources that I need to look at?
First try to unzip your war (wars, jars, ears are zip files) and see if your files are actually there, verify if your unzipped war contains:
dir WEB-INF
file WEB-INF/web.xml
dir WEB-INF/lib with the jars your aplication depends on
dir WEB-INF/classes with *.class files, where your servlets and related classes are supposed to be (if you have decided to have them there and not in a jar in WEB-INF/lib)
static resources in the root directory
You could make your conclusions of what is missing in your war.
You could also try to build your own war manually (creating a zip file with the structure I mentioned above and renaming it as *.war) if you have problems with doing it by your IDE's options
I use the jstl library in my project, but as an external jar. After exporting my project to a .war file, these libraries are not included and I'm getting errors. How do I make sure the library is included in my war file?
Also, an unrelated question, if an ear file would have only one war module, is there a point to making it an .ear instead of .war
If you have put the jstl jars inside WebContent directory they will be packed in your WAR file. But if you are loading them from somewhere else make sure that you have them in your export list (Project Properties -> Java Build Path -> Order and Export).
If you have an EAR file you can make some extra settings in your application.xml file, or even some container specific ones.
I'm pretty new to Maven and I've noticed an interesting thing in the Maven WAR Plugin.
When I package my Java web application with war:war, a zipped war is created. This war contains also the files pom.xml and pom.properties in the META-INF directory.
But if I package my application with war:exploded and create an exploded war directory, those two files won't be included.
Now I'm curious, why the pom.xml and the pom.properties aren't packaged into the exploded war. Besides those two files the contents of the exploded and the zipped war are equal.
Is there a reason why the plugin omits pom.xml and pom.properties from the exploded war?
Is there a reason why the plugin omits pom.xml and pom.properties from the exploded war?
The "component" that adds the pom.properties and the pom.xml files to the generated archive during war:war is the Maven Archiver. You can configure it with the archive optional parameter.
Interestingly, war:exploded also has this parameter but, at the moment, war:exploded doesn't process <archive> (see this comment of MWAR-86) and the exploded war currently doesn't match exactly the final war.
But without the pom files I can't run the exploded war on my local JBoss. So I can't test and debug it either.
The pom file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.xml and the pom.properties file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.properties are optional "metadata" and I'm not aware of any plugin relying on their presence. So I don't see why you can't run the exploded war on your local JBoss. Can you elaborate?
mvn war:war is intended to create a deployable artifact which needs the information inside (pom, MANIFEST.MF as well)...but the war:exploded is only intended for testing (deploy into a particular folder) instead.
Take a look at the explanation