Changes in source files of Maven project not reflected in tomcat - java

My maven project is in final stage. I have deployed my war file to running tomcat instance by using mvn tomcat7:deploy command and the war file is exploded in the webapps folder. I can access all the source files in the war file through url. But the problem is, when i change anything in my source files ( jsp and servlet ) the updated war file is not reflected in the running tomcat server.
my pom.xml is as follows.
<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>com.ceino.maven</groupId>
<artifactId>MavenWeb</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>MavenWeb 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>
</dependencies>
<build>
<finalName>MavenWeb</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<!--<warFile>/home/shebin/Maven Folder/MavenWeb/target/MavenWeb.war</warFile>-->
<server>TomcatServer</server>
<path>/MavenWeb</path>
<username>tomcat</username>
<password>tomcat</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
Am using maven 3.0.4 and tomcat 7.0.35. Pls help.

Try to call mvn clean install every time before running mvn tomcat7:deploy
If you still have the problem, try mvn tomcat7:undeploy before. The undeploy removes the old war file und the deploy try to push the new one

I used to have the same problem and I solved it adding this to the pom.xml file:
Here I'm synchronising 2 folders:
src/main/webapp/resources -> target/m2e-wtp/web-resources/resources
src/main/webapp/WEB-INF/views -> target/m2e-wtp/web-resources/WEB-INF/views
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/m2e-wtp/web-resources/resources</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-views</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/m2e-wtp/web-resources/WEB-INF/views</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/views</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

Related

Why is the spring-boot-maven plugin adding the war itself when repackaging an overlayed war file?

I have the following 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>org.example</groupId>
<artifactId>foo-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.jasig.portlet</groupId>
<artifactId>CalendarPortlet</artifactId>
<version>2.6.2</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
<overlay>
<groupId>org.jasig.portlet</groupId>
<artifactId>CalendarPortlet</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run mvn package the resulting repackaged war file contains the original war itself under WEB-INF/lib/CalendarPortlet-2.6.2.war.
Why does spring-boot add the war during repackaging and how do I prevent this?
In my real project I want to replace some resources of an already existing war and add the build-info for display by the actuator. But doubling the size of the artifact is not feasible just for that.
EDIT:
The problem also appears when repackaging jars.
Preventing the original artifact being included in the repackaged artifact can be achieved by manually specifying an exlclude for that artifact in the config of the spring-boot-maven plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<configuration>
<excludes>
<exclude>
<groupId>org.jasig.portlet</groupId>
<artifactId>CalendarPortlet</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
But I still don't know why that plugin includes the original artifact in the repackaged one.

Maven package add jars from dependencies to jar

I'm trying to create a jar from my maven project containing the jar files from dependencies in a specific folder.
The framework I'm writing a plugin for requires external dependencies to be supplied as jar files in the plugin jar.
For example:
xxxx.jar
/myapp/myjavaclasses
/lib/externalDependencies.jar
My pom 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>
<groupId>AAAAA</groupId>
<artifactId>BBBBBBB</artifactId>
<packaging>jar</packaging>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Rundeck-Plugin-Classnames>CCCCC</Rundeck-Plugin-Classnames>
<Rundeck-Plugin-Version>1.1</Rundeck-Plugin-Version>
<Rundeck-Plugin-Archive>true</Rundeck-Plugin-Archive>
<Rundeck-Plugin-File-Version>${project.version}</Rundeck-Plugin-File-Version>
<Rundeck-Plugin-Libs>lib/httpclient-4.5.8.jar lib/httpcore-4.4.11.jar</Rundeck-Plugin-Libs>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the above pom file we have the dependency
org.apache.httpcomponents
, this dependency contains the following jars
httpclient-4.5.8.jar
httpcore-4.4.11.jar
these jars need to be imported in my final jar under the folder /lib.
Thanks to #ernest_k came to a solution using
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
and
<resources>
<resource>
<directory>.</directory>
<includes>
<include>lib/**/*.jar</include>
</includes>
</resource>
</resources>

Java Maven Jasperreport run from Eclipse Ok, from with java - jar JRRuntimeException: Chart theme "eye.candy.sixties" not found

I created a Java program which creates a report with JasperReports.
In one of my JasperReports I use the theme="eye.candy.sixties".
when I run the project from Eclipse in the gui, all is fine, see
However when I build the same project with Maven and run it from the commandline I get the error:
Maven: clean compile assembly:single
Command line: java -jar chartTheme-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Exception in thread "main" net.sf.jasperreports.engine.JRRuntimeException: Chart theme "eye.candy.sixties" not found.
What am I missing, what should I change? Any help welcome!
Source code can be found on Github: ChartTheme
I did include the chart theme dependency in Maven, see the "Maven dependencies list in Eclipse:
and in the code below (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.lightroomstatistics.samples</groupId>
<artifactId>chartTheme</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>chartTheme</name>
<description>chartTheme</description>
<url>www.lightroomstatistics.com</url>
<organization>
<name>LightroomStatistics</name>
<url>www.lightroomstatistics.com</url>
</organization>
<parent>
<groupId>com.lightroomstatistics.maven</groupId>
<artifactId>lightroomstatistics-parent-pom</artifactId>
<version>1.0.0</version>
</parent>
<properties>
<java.version>1.8</java.version>
<jasperreports.version>6.4.0</jasperreports.version>
<jasperreportsfonts.version>4.0.0</jasperreportsfonts.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<repositories>
<!-- Needed for Jasperreports chart-themes -->
<repository>
<id>jr-ce-releases</id>
<name>JasperReports CE Releases</name>
<url>http://jaspersoft.jfrog.io/jaspersoft/jr-ce-releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>${jasperreportsfonts.version}</version>
</dependency>
<!-- jasperreports-chart-themes -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-chart-themes</artifactId>
<version>${jasperreports.version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>reports</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>data</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-report-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/reports</outputDirectory>
<resources>
<resource>
<directory>reports</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-data-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/data</outputDirectory>
<resources>
<resource>
<directory>data</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>chartTheme.ChartThemesApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you open your built joint-library chartTheme-0.0.1-SNAPSHOT-jar-with-dependencies.jar, you'll realize that the contents of file jasperreports-char-themes-6.4.0.jar/jasperreports_extension.properties are misssing, because they were overriden with the contents of some other jasperreports_extension.properties file also present in your dependencies.
In fact, if you search in the output console after running mvn assembly, you'll find these traces:
[INFO] jasperreports_extension.properties already added, skipping
... which, by the way, is not the only one file skipped at assembly.
So, definitely it's not a good idea to assembly all of these dependencies together, because of the overlaps. At least, not in this way.
I think the first thing you should try is to parametrize the assembly descriptor file to exclude the undesired files priorizing the desired ones, which I presume will be the ones in jasperreports-chart-themes.jar (by the traces in the log you posted).
Thank you for looking into this problem. Little Santi explained to me what was the problem.
Also not liking to have a big JAR, I decided to put all the dependency jar in a separate lib directory / folder. This worked fine.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>chartTheme.ChartThemesApp</mainClass>
</manifest>
</archive>
<finalName>${project.name}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven - maven-war-plugin to generate jar and install it to maven local repository

I am using maven-war-plugin in my pom.xml to generate a jar file in parallel with my war file in an java web project build. My maven build is creating war and jar files in the target directory. And only war file is installed to local repository. Is there a way to push the jar file created as well to local repository. Below is the snippet of my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<archiveClasses>true</archiveClasses>
<packagingExcludes>WEB-INF/lib/x*.jar</packagingExcludes>
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
<webResources>
<resource>
<directory>${project.basedir}\src\main\webapp</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
Thanks in advance!
pom.xml content:
<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>com.xyz</groupId>
<artifactId>x</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>x</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<archiveClasses>true</archiveClasses>
<packagingExcludes>WEB-INF/lib/x*.jar</packagingExcludes>
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
<webResources>
<resource>
<directory>${project.basedir}\src\main\webapp</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This is not the right way to use maven. Maven is all about modularity and as a consequence there is a "one project - one artifact" rule (or recommendation). See also this blog if I can't convince you : How to Create Two JARs from One Project (…and why you shouldn't) . It is about multiple jars but the concept is the same.
I think you should restructure your work into having one separate project for the jar, while the others use it as a dependency.

Maven pom looking for resources outside of jar

I'm having trouble creating an executable jar with all dependancies and resources packaged in it. So far I have everything inside the jar, but it is looking for the resources OUTside the jar.
Here is the structure of my project:
MyProject
----images
----resources
----src
----...
I'm able to Create the Executable Jar with dependancies packaged in, and the resources are packaged as well, however it is still looking for the resources in the "resources" folder and not IN the JAR.
The jar looks like this:
MyProject.jar
----images
----resources
----...
When I try run it, I get this error:
java.io.FileNotFoundException: .../MyProject/target/resources/default-style.xml (No such file or directory)
So my problem is this: my dependancies and resources are packaged in the jar like I want, but upon execution it's looking for "resources/" in the "target/" folder and NOT in the JAR.
Here's my pom:
<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>
<!-- MyProject INFO -->
<groupId>Main</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-beta</version>
<name>MyProject</name>
<packaging>jar</packaging>
<!-- DEPENDANCIES -->
<dependencies>
<dependency>
<groupId>custom</groupId>
<artifactId>custom</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>jgraphx</groupId>
<artifactId>jgraphx</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<!-- RESOURCES -->
<resources>
<resource>
<directory>src</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/images</directory>
<filtering>false</filtering>
<targetPath>images</targetPath>
</resource>
<resource>
<directory>${basedir}/resources</directory>
<filtering>false</filtering>
<targetPath>resources</targetPath>
</resource>
</resources>
<testResources>
<testResource>
<directory>src</directory>
</testResource>
</testResources>
<plugins>
<!-- For Java 6, you need to configure the maven-compiler-plugin. Add this to your pom.xml: -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- CREATE EXECUTABLE JAR WITH DEPENDANCIES -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
EDIT: Looks like it might be my code instead. I'll take a look, thanks! (My company's proxy blocks most of stackoverflow so I can't reply to comments >.< That's why I'm writing it here. Thanks Jigar Joshi and Aurand!)
Look into the java build path. The default output folder for the resources might be incorrect. May be that is why resource contents are not copied properly.

Categories

Resources