I have a Maven/Spring Boot project and resource folder with a mix of files with Latin and non Latin characters.
This is my pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<artifactId>example</artifactId>
<groupId>com.example</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<packaging>war</packaging>
<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding
</properties>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>false</addResources>
<jvmArguments>
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
</jvmArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<useDefaultDelimiters>true</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
</project>
Right now on the Linux(OpenSuse) machine after the Maven build(on Jenkins) I have two WAR files:
api-0.0.1.war.original
api-0.0.1.war
After unzipping of api-0.0.1.war.original everything looks good but in case of unzipping api-0.0.1.war all non-Latin characters in file names look like ??????. I noticed this after deploying my application to Tomcat.
What can be wrong and how to make it properly working with api-0.0.1.war also ?
UPDATED
As it was suggested at the comment, I have created a sample GitHub project that helps to reproduce the issue: Spring Boot Maven non-Latin characters in file names issue
The steps to reproduce:
Build project: mvn clean install
Deploy demo-0.0.1-SNAPSHOT.war to Tomcat 8 at OpenSuse
After deploy you will see the following issue with a file name:
Related
I am trying to exclude some files from a Maven war build by using profiles, and just cannot figure out to get that done.
I have created two profiles in pom.xml, created an eclipse run configuration for each, and can invoke them separately. But the resultant builds both have all the files in the eclipse project, no matter what I try.
I have simplified it to A and B, profile A is the 'default' profile.
<profile>
<id>profile-a</id>
<build>
<finalName>builda</finalName>
<plugins>
<plugin>
<artifactId>cloud</artifactId>
<version>11.0.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<classifier>profile-a</classifier>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
And profile B is the one where I want to remove some files, and have tried all sorts of ways, and have reduced it to not including anything, and all the possible exclude methods are shown also.
<profile>
<id>profile-B</id>
<build>
<finalName>buildb</finalName>
<plugins>
<plugin>
<artifactId>cloud</artifactId>
<version>11.0.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<classifier>cloud-service</classifier>
<excludes>
<exclude>**/*.txt</exclude>
</excludes>
<packagingExcludes>**/*.txt</packagingExcludes>
<warSourceExcludes>**/*.txt</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
But both builda.war and buildb.war are identical - I compared the war files with Beyond Compare, and the only difference is the timestamp in the Manifest. I also tried removing a .jar file just to see if it was something about .txt files, but no difference at all.
So I'm thinking that the build information is coming from my eclipse project not from pom.xml. Or I completely missing something - I am still a maven newbie, so that is entirely possible.
But how to get this done?
First of all I feel that I should point out that there seem to be multiple problems with the POM you've provided. I think you should take some time to read through the Maven POM Reference, Maven Build Lifecycle, and related documentation.
Based on what you provided I think you're trying to add a classifier to your artifact based on the profile that was active during the build. I preserved this functionality and corrected the other aspects of the POM as best I could, but I made a few assumptions.
Here is the modified 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>
<groupId>web.example</groupId>
<artifactId>exampleWar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile-a</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<classifier>profile-a</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile-b</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<classifier>profile-b</classifier>
<packagingExcludes>%regex[.*\.txt]</packagingExcludes>
<warSourceExcludes>%regex[.*\.txt]</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I'm compiling my project with mvn clean package, and failed with package does not exist.
The detail command:
Get the jar file target/xxxx.jar by running mvn clean package in source project.
install this jar file by running mvn install:install-file -Dfile=lib/xxxx.jar -DgroupId=com.company -DartifactId=source-package-name -Dversion=1.0.0 -Dpackaging=jar
add code to target project, which will use some functions in source project
compile target project by running mvn clean package, and it just failed with package does not exist
here is the source project 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>com.company</groupId>
<artifactId>source-package-name</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>source-package-name</name>
<description>xxxx</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx6144m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
here is the target project 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>com.company</groupId>
<artifactId>target-package-name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>target-package-name</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.7</jdk.version>
<smartv-common.version>0.3.5s</smartv-common.version>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!-- Exclude those since they are copied from the profile folder for
the build -->
<exclude>system.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<finalName>xxxxx</finalName>
<!-- Set a compiler level -->
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
http://stackoverflow.com/questions/12729513/how-to-overwrite-files-in-the-war-file-during-maven-build -->
<webResources>
<!-- Resources from the activated profile folder -->
<resource>
<targetPath>WEB-INF/classes/</targetPath>
<includes>
<include>system.properties</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
Ideally, you shouldn't use a Spring Boot application (something that's been repackaged) as a dependency. From the documentation:
Like a war file, a Spring Boot application is not intended to be used as a dependency. If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.
If the proposed solution isn't possible in your situation, the documentation goes on to describe an alternative:
If you cannot rearrange your code as recommended above, Spring Boot’s Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency. The executable archive cannot be used as a dependency as the executable jar format packages application classes in BOOT-INF/classes. This means that they cannot be found when the executable jar is used as a dependency.
To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as dependency.
To configure a classifier of exec in Maven, the following configuration can be used:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
I have he following structure of a maven web application
When I execute mvn install command it's creating war file but if you will look in target directory/sureportal you can easily see that lots of sub folders inside webapps directory are missing. What is wrong?
pom.xml file
<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.nokia</groupId>
<artifactId>sureportal</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>sureportal 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>sureportal</finalName>
</build>
</project>
You can have a maven-war-plugin and configure to include empty folders.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<includeEmptyDirectories>true</includeEmptyDirectories>
</configuration>
</plugin>
In addition to the answer of sbaitmangalkar, insert the maven-war-plugin to the build section of your POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!- if you don't have a web.xml, otherwise "true" -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<includeEmptyDirectories>true</includeEmptyDirectories>
<includes>**/*</includes>
<!-- if want your web files to be filterd -->
<webResources>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/META-INF</directory>
<!-- only if needed in your project -->
<targetPath>/META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
This tells the build process explicitly what to do.
Try running mvn clean install. This will clear your compiled files first and ensures that all of it is compiled from scratch. Please check this thread for more details how-is-mvn-clean-install-different-from-mvn-install
Good luck.
I have created a maven application with JSF, Spring and JSF facets. The goals clean (deleting the target directory) and compile are working fine. But when I am running Maven with package option, I see that in the generated xxx-SNAPSHOT.war file the webapp and WEB-INF directory are copied recursively.
The Maven version is 3.1.0.
Please see the 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.organization.elr</groupId>
<artifactId>employeerepository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Employee Location Repository</name>
<properties>
<version.spring>3.1.2.RELEASE</version.spring>
<version.aopalliance>1.0</version.aopalliance>
<version.standard.taglibs>1.1.2</version.standard.taglibs>
<version.commons.logging>1.1.1</version.commons.logging>
</properties>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${basedir}/src/main/WEB-INF/classes</outputDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<testOutputDirectory>${basedir}/src/main/WEB-INF/classes/test</testOutputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>${basedir}/src/main/webapp</webappDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Any ideas how I can avoid this?
Thanks in advance,
Mouli.
This makes no sense
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${basedir}/src/main/WEB-INF/classes</outputDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<testOutputDirectory>${basedir}/src/main/WEB-INF/classes/test</testOutputDirectory>
Remove those lines. You're building application to source dir.
This have no sense as well
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
Why do you have .java files in resources in the first place?
Is it possible to isolate integration tests from unit tests within same module?
I created simple 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>
<artifactId>prj</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/integration/**/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/integration/**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
however with mvn -Pintegration test it doesn't invoke anything. If I comment out excludes section in main build - then it starts to execute tests, but without profile as well.
instead of:
<exclude>*/integration/**/*.java</exclude>
try:
<include>*/unit/**.java</include>
then in the integration profile do
<includes>
<exclude>**/unit/**/*.java</exclude>
<include>**/integration/**/*.java</include>
</includes>
you may have to play with getting the includes/excludes exactly right, but that's the general idea.