I have a project which contains shared resources for several sub-projects; i.e. as well as Java code, it contains css and javascript.
My child sub-projects are packaged as jars using the maven assembly plugin. For some reason these do not include the css and js resources from the parent library.
So my question is simple: how can I configure the projects so that this happens? I don't want the child projects to be wars; they are dropwizard (/jetty) projects that run as standalone jars.
EDIT - I should make explicit that the resources are included in the parent project's jar; it's only when assembly (on a child project) includes the jar that they somehow go missing.
Parent pom:
<?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>io.parentproject</groupId>
<artifactId>parentproject</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
...
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>**/*.gwt.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
...
</plugins>
</build>
</project>
Example child pom:
<?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>io.child</groupId>
<artifactId>child</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Child</name>
<dependencies>
<dependency>
<groupId>io.parentproject</groupId>
<artifactId>parentproject</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>
true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>io.childproject.SomeClass</mainClass>
</manifest>
</archive>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
</project>
So my question is simple: how can I configure the projects so that this happens? I don't want the child projects to be wars; they are dropwizard (/jetty) projects that run as standalone jars.>
You need to add resource directory in <resource></resource> so that it picks up while building jar
You could either use maven-assembly plugin or configure your pom.xml to have these resources files specified as maven resources, assembly plugin will give you much more flexibility
I ended up using maven shade instead. It's a little more heavyweight than assembly but it does the job.
Still, if anybody knows how to make assembly do this please add an answer.
Related
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>
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>
I am a newbie when it comes to Maven, and so really struggling to solve the following problem because a colleague with real knowledge in this area has moved onto fresh pastures. Would really appreciate pointers to where I might be going wrong; I realise there must be lots of questions on StackOverflow about Maven & Eclipse classpaths, but having searched some of them, I need to ask in my own terms because of my lack of experience - sorry.
Some files are attached which I hope will be enough to form the equivalent of an SSCCE in pure Maven POM terms. The Java itself is irrelevant and subject to obvious confidentiality, but I can provide more info if needed.
So I have a small Maven project providing my own API for a third-party software protection dongle (DinKey, from Microcosm). The project is called dinkeypro with half a dozen of my classes which reference the manufacturer's class that reads/writes the dongle, namely DinkeyPro.class. This class is held inside DinkeyPro.JAR, which I reference as a dependency using a SystemPath and, as you can see from the following POM, I've tried two different SystemPath specs. Just for reference, note that the manufacturer requires the package structure for the class file to be:
uk/microcosm/dinkeydongle/DinkeyPro.class
Here is the POM for dinkeypro, with irrelevant dependencies removed for brevity/readability:
<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.xyz</groupId>
<artifactId>dinkeypro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>DinkeyPro API</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>dinkeyjar</groupId>
<artifactId>dinkeyjar</artifactId>
<scope>system</scope>
<version>1.0</version>
<!--<systemPath>${basedir}\src\main\resources\DinkeyPro.jar</systemPath>-->
<systemPath>C:\Dev\core_dinkeypro\src\main\resources\DinkeyPro.jar</systemPath>
</dependency>
</dependencies>
</project>
Access to the dongle API is required from two other Maven projects, 'client' and 'server'. They both appear to specify the exact same Maven dependency on dinkeypro (see POMs below) although, admittedly, client and server are structured differently in terms of folders (server uses the more recognisable src/main/java paradigm but the client does not, and I'm wondering if this is the source of the problem.
What happens is that the client project runs and successfully reads the dongle via my API, whilst the server throws:
Exception in thread "main" java.lang.NoClassDefFoundError: uk/microcosm/dinkeydongle/DinkeyPro
at com.xyz.dinkeypro.SoftwareProtectionReadOnlyAgent.isProtectionDevicePresent(SoftwareProtectionReadOnlyAgent.java:73)
at com.xyz.soft.ServerApp.initialize(ServerApp.java:1200)
at com.xyz.soft.ServerApp.main(ServerApp.java:310)
Caused by: java.lang.ClassNotFoundException: uk.microcosm.dinkeydongle.DinkeyPro
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
Here is the POM for client, which runs OK:
<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.xyz.soft</groupId>
<artifactId>client</artifactId>
<version>0.5.0-SNAPSHOT</version>
<name>client</name>
<description>client</description>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target-resource</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/target-resource</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>client</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xyz.client.ClientApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>dinkeypro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Here is the POM for the server which has the classpath problem:
<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.xyz.soft</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>server</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>additional-target-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target-resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/target-resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>run</id>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.xyz.server.ServerApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>ebmsCore</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xyz.server.ServerApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>dinkeypro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I've examined the content of both the built client and server JAR files. They both contain DinkeyPro.JAR at the root of their own JAR, and both can navigate from the root to com.xyz.dinkeypro.
So, confusion reigns. Can anyone shed any light on what I've done wrong ? As you can see, I am valiantly trying to keep with Maven, simply so that future changes to dinkeypro API can just roll through to client and server (and any other projects that may need it one day...). However, if this gets to be too much of a minefield, I may just have to place a copy of DinkeyPro.JAR in the resources folder of the server project so that I can move on.
Many thanks
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.
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.