I have this set, and everything working fine on a Windows box during tests, Deployment to unix box for testing, the folder is missing and is not created :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Its location is conventional here:
src/main/resources/myfolder
It's deployed as a war, and the directory is not created in WEB-INF/classes.
The rest of my pom looks like this:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/myfolder</directory>
</resource>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
Related
This is my problem: I have a Maven project that is using a Swing library and it is a GUI app which I want to include a resources (images and one config.properties file) in my jar file.
Here is my pom.xml code:
<build>
<resources>
<resource>
<directory>${basedir}/resource</directory>
<includes>
<include>**/*.png</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>${basedir}/config</directory>
<includes>
<include>config.properties</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>.settings</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>bis.debug.mode.ui.MainBISDebugMode</mainClass>
</manifest>
</archive>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
and here is my structure to my project:
I included directories as it seen in the pom.xml and the files in it and still doesn't included in jar file and it doesn't see images on the GUI app. When I run the program as Java application everything is fine.
Is it possible to be something wrong in my code? How I can fix the problem?
You need only to put your config file in src/main/resources and no need to add resources in pom.xml because src/main/resources is the maven's default resources folder
I googled for my issue but I was not able in finding solution; I'm using maven 3.1.2
I have this profile in my pom.xml
<profile>
<id>test</id>
<build>
<finalName>CustomWebAppName</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>environmentConfiguration.properties</exclude>
</excludes>
</resource>
<resource>
<directory>resourcesTest</directory>
<includes>
<include>environmentConfiguration.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputDirectory>testDist</outputDirectory>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
As you can see I'm simply telling maven: when you build the test profile you must ignore the file "environmentConfiguration.properties" in folder src/main/resources and consider the file "environmentConfiguration.properties" in resourcesTest
Well when I launch the command mvn clean install -P test my final web application always contains the "environmentConfiguration.properties" file located in src/main/resources and doesn't contain the one in resourcesTest
I add to the question my fully debug log file generated by maven
Please note this file will be available till November 12nd 2015
Can anybody tell me where I'm wrong?
thank you
Angelo
I don't know exactly whether this is your problem or a typo in your question but there shouldn't be any space between -P and test
try this instead
mvn clean install -Ptest
EDIT
try to enable filtering
<profile>
<id>test</id>
<build>
<finalName>CustomWebAppName</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>environmentConfiguration.properties</exclude>
</excludes>
</resource>
<resource>
<directory>resourcesTest</directory>
<filtering>true</filtering>
<includes>
<include>environmentConfiguration.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputDirectory>testDist</outputDirectory>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
I have another maven structural problem... =/
a sample project with 3 different modules:
CONFIG (contains all configurations files)
DAO (depends on CONFIG)
SERVICE (depends on DAO and CONFIG)
The CONFIG module generates filtered resources in it's "target" folder by using the "maven-resources-plugin". How can the DAO and SERVICE modules access those filtered resources?
help help plz help =)
here's the resource filter part of the CONFIG modules POM:
<build>
<filters>
<filter>src/main/resources/basic.properties</filter>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/context*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The CONFIG module should be producing a JAR with the filtered resources in its root. The other modules should be able to access those resources via their classpaths, which should contain the CONFIG jar, using ClassLoader.getResource(String) or ClassLoader.getResourceAsStream(String).
EDIT: after comment below.
You don't need to re-declare the Resources plugin, you simple specify the resources in the build section of the pom like this:
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/context*.xml</include>
</includes>
</resource>
</resources>
</build>
Facing issue “/hibernate.cfg.xml not found” while executing OSGi bundle.
I have created a OSGi bundle through Apache felix bundle plugin, in my bundle I am connecting database through hibernate. When I execute my bundle in OSGi container it throws error. I have added all hibernate related xml files (like hibernate.cfg.xml) through resources tag in POM.xml file in the root folder of the bundle.
Error is
SessionFactory creation failed:org.hibernate.HibernateException: /hibernate.cfg.xml not found
This may be minor issue but I could not figure it out, please help me to resolve the issue
This is my POM.xml file
……… …….................
..................................................
<build>
<sourceDirectory>D:\WSNew\HCB-VCDPlugin100\src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<excludeDependencies>*;scope=provided|runtime</excludeDependencies>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
<!-- Export-Package>${project.exports}</Export-Package> -->
<!--<_exportcontents>${project.exports}</_exportcontents> -->
<Import-Package>org.osgi.framework, ,org.apache.log4j,org.hibernate,org.hibernate.cfg,org.hibernate.transform,org.quartz,org.quartz.impl,javax.xml.transform,org.w3c.dom,org.xml.sax,javax.xml.parsers,!*</Import-Package>
<Bundle-Activator>com.abclcorp.hcb.vddservice.impl.Activator</Bundle-Activator>
<!-- <Private-Package>org.foo.myproject.*</Private-Package> -->
<_exportcontents>*</_exportcontents>
</instructions>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>resources/configuration</directory>
<includes>
<include>CronScheduler.xml</include>
</includes>
</resource>
<resource>
<directory>resources/log4j</directory>
<includes>
<include>log4j.properties</include>
</includes>
</resource>
<resource>
<directory>resources/logs</directory>
<includes>
<include>CronScheduler.log</include>
</includes>
</resource>
<resource>
<directory>src</directory>
<includes>
<include>*.xml</include>
</includes>
</resource>
</resources>
</build>
I am trying to add some filtering to the application context file, which resides in the WEB-INF directory.
I have the file which is to be filtered (xmlgateway-context.xml) in the folder /src/main/resources.
I have the properties files (config-e05.properties) in the folder src/main/filters
And I have the POM set up as follows:
<!-- environment profiles -->
<profiles>
<profile>
<id>e04</id>
<properties>
<targetenv>e04</targetenv>
</properties>
</profile>
<profile>
<id>e05</id>
<properties>
<targetenv>e05</targetenv>
</properties>
</profile>
</profiles>
<!-- build settings (filtering) -->
<build>
<filters>
<filter>src/main/filters/config-${targetenv}.properties</filter>
</filters>
<resources>
<resource>
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
This will mvn install correctly, but when I open the output war file, I was expecting the file xmlgateway-context.xml to be in the /WEB-INF directory, but it ends up in the folder /WEB-INF/classes/WEB-INF.
How can I get this file into the right place.
Alternatively, can I put the application context into a different location and have it referenced there.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/xmlgateway-context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
Add the above to your pom.xml.
EDIT: Just to explain what the above conf is doing. With this added, mvn is going to filter files under src/main/webapp/WEB-INF and in particular filter the included files xmlgateway-context.xml and after filtering it is going to push the files in WEB-INF folder (thats what the target tag is saying).
Update if something is not clear.
you should configure filtering via the maven war plugin: checkout these examples.
With filteringDeploymentDescriptors set to true
<build>
<finalName>web-project-name</finalName>
<filters>
<filter>src/main/resources/app.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</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>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
Put the file xmlgateway-context.xml in src/main/webapp/WEB-INF and configure like this:
<build>
<filters>
<filter>src/main/filters/config-${targetenv}.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp/WEB-INF</directory>
</resource>
</resources>
</build>