Maven *.xml resorces not updated after build - java

I recently found that some changes that I make in files are not reflected in target war - it happens only when I don't make any changes to java code, so the compilation phase is omitted. Is there a better way to force compilation than meaningless code changes like renaming variables or is there a way to update *.xml content?
EDIT:Here is my pom.xml
<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>com.example</groupId>
<artifactId>hiring</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine</artifactId>
<version>7.0.0-Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>camunda-bpm-nexus</id>
<name>camunda-bpm-nexus</name>
<url>https://app.camunda.com/nexus/content/groups/public</url>
</repository>
</repositories>
</project>
All xml files are at src/main/resources
I'm using Eclipse Keppler Service Release 1 with Maven 3.2.1, Java 1.7.0_17

Make sure you have m2e/m2e-wtp installed
Make sure Eclipse applies the Maven project nature to the project - Right click project > Configure > Convert to Maven Project.
If you edit a file outside Eclipse, make sure Eclipse knows about the change -- you need to enable native hooks -- Preferences > General > Workspace > Refresh using native hooks or polling. Alternatively, you can select the file and hit F5 (refresh) to make sure Eclipse is aware of the change.
Hit publish if you're using WST/JST (server tools) and deploying to a server via Eclipse.
In my experience if you've done all this, it should publish the changes to your target war as expected. Though, you may need to restart the container if the XML files are used as part of the startup configuration.

Related

maven war plugin does not forget about old files and dependencies and creates a war that contains removed files and dependencies

Hello I'm having a weird problem about war creation.
I use maven-war-plugin (tried with 3.1.0, 3.2.0, and 2.6). When I run war:war (or mvn clean package, or similars) the war is created but I noticed that it is like it always packages all the files and dependencies it encountered in the history of the project. I noticed this because the war file is always getting bigger and by opening it I see there are a lot of dependencies that I declared on the pom but now they are removed, and most importantly there are classes I deleted from the project! I even tried to start a new project and the result does not change.
I guess I'm using this badly... Is there something I should do to let him "forget" about the history and force it to consider the project "as it is" when creating a war?
Thanks for the help!
PS:
I always clean and compile before running war:war;
I work with IntelliJ IDEA Community 2017.3
using jdk 1.7 because of technical constraints.
Just for completeness, there is my pom.xml:
<?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>
<groupId>sduca-consumer-listener</groupId>
<artifactId>sduca-consumer-listener</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webappDirectory>/sduca</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Using Spring 4 because of jdk 1.7 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
EDIT1: I tried to change versions of maven-war-plugin, maven-compiler-plugin, and Maven itself, but nothing changes.
EDIT2: I tried changing the output directory, no changes. I tried to change version of the dependencies and as "expected" now the war includes both versions, becoming bigger and bigger...
EDIT3: I reinstalled IntelliJ IDEA, upgrading to the latest version. Nothing changes, it has only reset the content of the package, but it still "keep track" of the content and dependencies and still includes removed stuff on the package when creating a new one.
EDIT4: I've started using mvn clean compile war:war instead of mvn clean package and at first things started working, but then the problem of the existing old files returned. However, I find out that if I manually remove the exceding resources and *.class from the war it looks it works (at least it's deployed).
It's just a trick worked for me many times,
Backup your dependencies from pom.xml and delete it.
Do a clean build, it will show errors in all Java classes. Also delete the previous war.
Now, replace those backed up dependencies and clean build the webapp again. All errors will be disappeared and war file will be as expected.

Manually launched Spring Boot application from .jar not working properly

The problem is when I run .jar file(Spring Boot MVC app) from Intellij IDEA, application works fine, but when I try to run same file from the command line, template resolver cannot find template(.html) files. And this seems to be reasonable since when I opened .jar with file archiver I did not find any traces of that files.
How Intellij make it work proper? And how can I do the same?
My project structure:
here they are, in '/templates' folder
.jar file opened in archiver:
As I said, there is no .html files, so how Intellij add them when running .jar?
pom.xml:
<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>com.vlad.pet.contactlist</groupId>
<artifactId>web-app</artifactId>
<version>1.0-ALPHA</version>
<packaging>jar</packaging>
<name>web-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>com.vlad.pet.contactlist</groupId>
<artifactId>model</artifactId>
<version>1.1-inmemory</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
A normal Spring Boot application built from http://start.spring.io would show the templates folder within the src/main/resources. This is because by default the contents of that folder are made available to the classpath and packaged at the root of the jar file. I am guessing you modified the project in IntelliJ to also pick up the src/main/webapp directory. Unfortunately that doesn't work when it comes to packaging the jar. You would need to work with the maven resources plugin to specify the additional directory to be included in the jar file.
My recommendation is to go to start.spring.io. Select Web and Thymeleaf as dependencies and then download the zip file. When you look in that file you will see the default structure along with settings for any plugins to make it work. Mirror that structure within you application.
If you don't have the ability to change the project structure then check out the maven-resources-plugin for specifics on how to add those directories.
You can see what exactly IntelliJ is doing, by looking at first line in its console after running app. There should be full command called by IntelliJ.
And how .jar is build? Maven/Gradle? maybe there's some problem with pom/build script
It should be comment, but my reputation is too low
Try to use the plugin to generate an executable jar:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
After building the jar (e.g. mvn clean install), you can run the jar as java -jar ./target/project.jar

How to place folder/jar in Maven META-INF root

I am working on a implementation that requires UnlimitedJCEPolicyJDK8 for SAP hana cloud platform. The documentation tells me that i need to place it under the following structure:
WAR file:
META-inf
- ext_security
- jre8
The problem is when i include the jars it goes to WEB-INF/classes and thats not where the server is looking. As seen in the picture.
Technical details:
tomcat 8: v3.2 runtime
JRE 1.8
Maven build: using webapp archatype
With facades to support servlets.
IDE: eclipse
Tried the following:
add files using eclipse web deployment assembly (for what ever the reason it does not seems to work with maven and yes i use .m2 and WTP plugin)
Adding files trough maven dependency and tried copy to output folder.
i open WAR file moved files manually to correct folder and re-zipped and verified that if its in correct folder the update to server is working fine.
i really hope you can help me.
kind regards,
UPDATE: as requested by khmarbaise the pom file. And i created web-inf folder by myself in the hope it would be placed in root.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hcp</groupId>
<artifactId>edi.web</artifactId>
<packaging>war</packaging>
<version>0.0.2-SNAPSHOT</version>
<name>edi.web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- tried classpath but it did not seem to do annything
Below dependency is from local .m2 repository-->
<dependency>
<groupId>hcp</groupId>
<artifactId>jre8security</artifactId>
<version>1.0.0</version>
<optional>true</optional>
<!-- goes in manifest classpath, but not included in WEB-INF/lib -->
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution provided by pace:
create a source folder under the following name: src/main/webapp/META-INF
The maven-war-plugin's war goal has a configuration option webappDirectory. It defaults to src/main/webapp. Anything in there will be placed in the root of the war. So you could create a directory:
src/main/webapp/META-INF
and drop in whatever files you want there. I don't much about the web tools plugin so not sure what approach would work there.

no native library found for maven plugin project

I want to integrate a leap motion app into Weasis Dicom Viewer.
Projects:
Weasis-maven-plugin -> where my leap implementation is
Weasis-framework -> dicom viewer
Weasis-launcher -> This is where I launch the Dicom viewer.
What I've done already:
have m2e with eclipse and added the LeapJava.jar to plugin project and set the location of the native library
installed LeapJava.jar into the .m2/repository folder so that mvn install on my maven plugin build succeeds
added into the pom.xml of maven-plugin
updated maven project
what doesn't work:
when i launch the application, I get no LeapJava in java.library.path
I've seen some other threads that says I need to manually add -Djava.library.path to the VM arguments. However, when I add that to the launcher run config in eclipse the library not found still exists. Should I be adding this somewhere? Any help is greatly appreciated.
This is my pom.xml for the weasis-plugin:
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>weasis-parent</artifactId>
<groupId>org.weasis</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../weasis-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>LeapPlugin</groupId>
<artifactId>UBC</artifactId>
<packaging>bundle</packaging>
<name>Tool panel sample [${project.artifactId}]</name>
<properties>
<bundle.symbolicName>${project.artifactId}</bundle.symbolicName>
</properties>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Service-Component>OSGI-INF/*.xml</Service-Component>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-ui</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.dicom</groupId>
<artifactId>weasis-dicom-viewer2d</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/sdk/LeapJava.jar</systemPath>
</dependency>
</dependencies>
When I add the "systemPath" I can still mvn install properly but when i run the launcher project now I get org.osgi.framework.BundleException: "Unresolved constraint in bundle"
UPDATE 1:
So right now this is what my pom.xml looks like
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no leapMotion-1.0.0 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at weasisTool.SampleTool$1.run(SampleTool.java:98)
Not sure if this is the actual solution.
But I added:
nativedependency-plugin in my pom.xml
made sure to do mvn package on the plugin project folder (this generated some files under target/ folder
added -Djava.library.path to the VM argument and it compiles and runs!

Maven error when pom.xml is packaged an ejb, but goes away when packaged as jar

When I package my pom.xml as an EJB I get an error that I do not understand. This error shows up if I touch the package in any way, to include Ctrl+S and Maven update. The error goes away if I change the packaging back to jar.
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>
<parent>
<groupId>com.myorg.buildparent</groupId>
<artifactId>BuildParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.myorg.myEjbPackage</groupId>
<artifactId>MyEjbPackage</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ejb</packaging>
</project>
By changing
<packaging>ejb</packaging>
to
<packaging>jar</packaging>
The error will go away.
Error string for reference:
'Building workspace' has encountered a problem.
Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'MyEjbPackage'.
org.codehaus.plexus.archiver.ArchiverException
Even though I can remove the error, I still feel like it should be packaged as an ejb. Does this make sense to anyone? Does my EJB package need to be packaged as a EJB in the pom? I should admit that my skills with Maven are around that of a novice/low intermediate.
Try adding this configuration in your POM. The EJB plugin (which is bound to the lifecycle by default when you select ejb packaging type) doesn't use the same version of the archiver that the jar/war/ear plugins do.
There is a JIRA issue for updating the dependency versions, however it has not been worked yet.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${maven.ejb.plugin.version}</version>
<dependencies>
<!-- Use the same archiver as the other [j/w/e]-ar plugins -->
<!-- See http://jira.codehaus.org/browse/MEJB-52 -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
Update
MEJB-52 is fixed in maven-ejb-plugin version 2.4 and later. Consider updating the plugin version to the latest before adding this configuration.

Categories