How I can override charset in Maven? - java

if I run my java maven project from Eclipse I don't habe problems. All encodings are UFT-8, but if I compile with
maven clean package
I have problems with the encoding on some different places. XSLT-transform, SOAP and so on.
I found some tricks in the Internet, but nothing helps. What can I do?
Things I tested with no effect:
pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
On console:
mvn -DargLine=-Dfile.encoding=UTF-8 clean package
$ mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T20:49:05+01:00)
Maven home: C:\Program Files\apache-maven-3.5.3
Java version: 1.8.0_201, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_201\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
The Platform encoding is CP1252.
How can I say maven to use UTF-8, Eclipse can do it.
Thanks for any help.
UPDATE:
I enabled the DEBUG output from Eclipse, there are this lines:
Maven home: C:\Users\EMBEDDED
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_201\jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
platform encoding: UTF-8 <- How can I do this
UPDATE 2:
Setting Systemvariable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8 helps. Now it works.

Related

Maven non-interactive mode (batch) prevent's project extensions loading

I'm trying to use Takari SmartBuilder in a Maven project under Jenkins.
After testing it locally everything was working perfectly, but in Jenkins the Takari extension is not loaded.
After some investigation I found that maven's "-B" option order was preventing the projects extensions to load.
Not loading extensions:
mvn -B -f <project-name>/pom.xml clean install -X
Loading extensions:
mvn -f <project-name>/pom.xml -B clean install -X
Extensions are set in the root project folder under .mvn/extensions.xml
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.maven</groupId>
<artifactId>takari-smart-builder</artifactId>
<version>0.4.0</version>
</extension>
<extension>
<groupId>io.takari.aether</groupId>
<artifactId>takari-concurrent-localrepo</artifactId>
<version>0.0.7</version>
</extension>
<extension>
<groupId>io.takari.aether</groupId>
<artifactId>aether-connector-okhttp</artifactId>
<version>1.0.1-alpha</version>
</extension>
</extensions>
Versions:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /opt/maven-versions/apache-maven-3.3.9
Java version: 1.7.0_65, vendor: Oracle Corporation
Java home: /opt/java-versions/jdk1.7.0_65/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.13.1.el7.x86_64", arch: "amd64", family: "unix"
I believe I am facing a similar issue.
see https://issues.jenkins.io/browse/JENKINS-70357
It seems that the Jenkins Maven Integration Plugin is injecting the -B parameter unconditionally and for a good reason I am afraid.
However, either with or without interactive mode enabled, the extensions are loaded successfully (from lib/ext though), which proves that interactive mode does not control extensions in any way.
Also, using MavenJob offers some substantial advantages, like triggering downstream builds etc., which cannot be used with FreeStyleJob, making use of MavenJob necessary for certain development environments.

mvn invalid target release: 1.7

mvn test :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project vslimit: Fatal error compiling: invalid target release: 1.7.0_65
pom:
<java-version>1.7</java-version>
`<plugin>`
`<groupId>org.apache.maven.plugins</groupId>`
`<artifactId>maven-compiler-plugin</artifactId>`
`<version>3.2</version>`
`<configuration>`
`<source>${java.version}</source>`
`<target>${java.version}</target>`
`<encoding>${project.build.sourceEncoding}</encoding>`
`</configuration>`
`</plugin>`
java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
mvn -v
Apache Maven 3.2.1 Maven home:
/Users/vslimit/tool/apache-maven-3.2.1 Java version: 1.7.0_65, vendor:
Oracle Corporation Java home:
/Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/jre
Default locale: platform encoding: UTF-8 OS name: "mac os x",
version: "10.10.2", arch: "x86_64", family: "mac"
i has try a lot of suggests,ex:java_home or other,but failed
change your pom.xml to have
<project>
...
<properties>
<java.version>1.7</java.version>
</properties>
...
</project>

create maven project failed

I create a simple maven project in eclipse(indigo), it reports an error:
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.4.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.4.3
I found maven-resources-plugin:2.5 in local repo.
I don't understand why my project needs 2.4.3 but not 2.5?
mvn -v:
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: D:\Program Files\maven-3.0
Java version: 1.6.0_31, vendor: Sun Microsystems Inc.
Java home: D:\Program Files\Java\jdk1.6.0_31\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
I solved it,
just create src/main/java, src/main/resources, src/test/java, src/test/resources
The maven-resources-plugin will disappear.

Maven compilation error. Failure executing javac, but could not parse the error:javac: invalid flag: -s

I am getting a compilation error when try to execute mvn clean install.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid flag: -s
Usage: javac <options> <source files>
Java version is
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)
Maven version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Sajith\apache-maven-3.0.3\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.sample</groupId>
<artifactId>TestApp</artifactId>
<description>TestApp Release 1.0 Build</description>
<version>2.0</version>
<packaging>pom</packaging>
<name>TestApp API</name>
<url>http://maven.apache.org</url>
Any help would be appreciated.
The problem is that your maven is using java 5 (as your comment says). You have to change your JAVA_HOME variable to point to jdk 6 or higher. Look at :
Error when using javac: "javac: invalid flag: -s"
In my case i dont have the apropiate environment variable because the project is inherited, and I had not created the variable JDK_WAS85_JDK8 = C:\Program Files\Java\jdk1.8.0_221.
Usually is JAVA_HOME the variable that is set.

Maven doesnt use specified source and target settings

I'm trying to build a java project using maven. In the pom.xml file at the root of the project I have the following lines:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
but when I try to build with mvn -DskipTests -U install, I get the following error: static import declarations are not supported in -source 1.3
maven is not using the source and target (1.6) that i've specified in the pom.
java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
mvn --version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-21-generic", arch: "amd64", family: "unix"
uname -a
Linux ubuntu 3.5.0-21-generic #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Is there anywhere else that maven might be getting its default source and target settings from? Why isnt it using the settings from the pom?
Here is a snippet of error message when maven is ran in debug mode:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
[ERROR] /path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins: maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
/path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
Try setting the source level and source encoding with the following properties:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Try to clear you local Maven repo and run your build again (maybe, try also to run it with '-o' option)

Categories

Resources