I am having a Maven-Project which is configured using the following properties:
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
On my machine everything works fine with these settings. However, on another machine, when I check it out and try to build it using mvn install the compiler errors unmappable character for encoding ASCII:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project scuttle: Compilation failure: Compilation failure:
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,39] error: unmappable character for encoding ASCII
[ERROR]
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,40] error: unmappable character for encoding ASCII
[ERROR]
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,30] error: unmappable character for encoding ASCII
[ERROR]
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,31] error: unmappable character for encoding ASCII
I've already tried running mvn with -Dfile.encoding=UTF-8 but that did not help. $LC_CTYPE reports UTF-8.
What can I do?
You can see the complete pom file here: https://github.com/scravy/scuttle/blob/master/pom.xml
In the end the comment by khmarbaise helped me find a solution:
I configured the compiler plugin and specified the source encoding there, now everything works everywhere:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
You have all the right settings in your pom, so that's good. Verify your IDE (and the others used by your team if applicable) is configured for UTF-8.
Next, clean out your local .m2 repository and run your build again. It might be possible one of your transitive dependencies wasn't compiled with the right encoding. But you may have the "right" version in your .m2 that makes everything OK while the same version doesn't exist on the other machine.
Good luck! I know how annoying this stuff can be.
Instead of setting maven opts, set new environmental variable - JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF8
Related
As I am not expert for maven, I'm a bit lost here. We have projects which fail with the following error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7:site (default-cli) on project xxxx: Execution default-cli of goal org.apache.maven.plugins:maven-site-plugin:3.7:site failed: Invalid byte tag in constant pool: 18 -> [Help 1]
when executing this command
mvn site:site site-deploy -e -U
This occurs since we switched to java 8 and to my understanding it is somehow related to Java 8 and BCEL. However the message in the bug report is not exactly the same so I am not sure how or what do I have to configure to overcome the problem.
Here the essential info on how we have configured the site-plugin in the parent pom:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.6</version>
<configuration>
<locales>en</locales>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>${wagon.webdav.version}</version>
</dependency>
</dependencies>
Actually a rather stupid error. The issue was with the used clirr which was 2.3
08:26:16 [INFO] <<< clirr-maven-plugin:2.3:clirr < compile # xxxxx <<<
Actually clirr was configured in the parent pom to use 2.8
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
<version>2.8</version>
</plugin>
However, in the local maven repository there was still an outdated parent pom which refered to 2.3 instead 2.8. Deleting the parent pom from the local repo forced the re-download of the parent pom and now we are using the correct configuration
I know that there are a lot question with similar error. I would appreciate before point as duplicate take in account that it only happens with Java 9.
I do have java 9 installed
C:\_pocs\ws_j9\java9-http-client>java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
C:\_pocs\ws_j9\java9-http-client>echo %JAVA_HOME%
C:\Program Files\Java\jdk-9.0.1
To make simple the exemplification, if i download a very simple example https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/ and I try/
mvn clean install package -e
[ERROR] Failed to parse module-info:
[ERROR] With qdox: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.925 s
[INFO] Finished at: 2018-01-01T23:43:32+01:00
[INFO] Final Memory: 13M/44M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project http_client: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project http_client: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
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.javacodegeeks.java9</groupId>
<artifactId>http_client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java9HttpClient</name>
<description>Java Http Client example</description>
<properties>
<java-version>1.9</java-version>
<maven-compiler-plugin-version>3.6.1</maven-compiler-plugin-version>
<maven-shade-plugin-version>3.0.0</maven-shade-plugin-version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin-version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.javacodegeeks.java9.http_client.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I am bit confused what could be causing this issue. On top of this, I am facing another challenge that make it a bit harder for someone trying to use Java 9 for first time: my Eclipse isn't properly accepting Java 9. I tried install Java 9 Support in Eclipse Oxygen which I just downloaded it but I am getting "No repository found at http://download.eclipse.org/eclipse/updates/none". And I can't make this mvn plugin update the Java version to 9 (it used to work properly for Java < 1.8:
<properties>
<java-version>1.9</java-version>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<verbose>true</verbose>
</configuration>
</plugin>
That is the reason I am trying to compile straich from command line.
I read that Java 9 came with new concept of modularity which will help us better organize the packages but I am very limeted if this could drive me to fix my issue. It might be some obvious solution whe someone sees "Failed to parse module-info" but I can't imagine anything usefull to try.
My straight question is what I could check in order to compile. An additional trick regard making Eclipse Oxygen current version compatible with Java 9 will be appreciatte as well.
Edited
Eclipse version downloaded for Windows less than 24 hours ago:
Eclipse Java EE IDE for Web Developers.
Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600
Edited second time
After I changed from 1.9 to 9 the red error icon was gone and I have now Java 9. Nevertheless, now I got this error:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.542 s
[INFO] Finished at: 2018-01-02T05:19:30+01:00
[INFO] Final Memory: 9M/30M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project http_client: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Which doesn't make sense to me because:
Edited third time
In short, add a missing/misplaced class named module-info.java to include your project's module declaration at your project's source root. (e.g src/main/java)
Additionally, note to upgrade to the version 3.7.0 of the maven-compiler-plugin in case you have a comment included in your module-info class. [The logs seems pretty relevant to this.]
Or the other way, if you wish to compile your project with a previous version of Java then use the release flag as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>8</release>
<verbose>true</verbose>
</configuration>
</plugin>
Concepts
With Java9 marking the completion of the project Jigsaw therein introducing the Java Platform Module System (JPMS), projects build on Java version 9 and above would be modularised. This would include a primary compiled class called module-info.class which is that module's declaration.
The initial draft and eventually The State of the Module System describes best over the concepts followed and practiced.
An additional trick regard making Eclipse Oxygen current version
compatible with Java 9
AFAIK the latest Oxygen builds (Oxygen.2 at this point in time) from Eclipse are meant to be Java9 compatible without any additional plugin support anymore.
Additional Useful Resources:
JDK9 Migration Guide
Maven compiler plugin's example over module-info inclusion and exclusion
in the second edit, you have to add jdk to your build path. Go to windows->Preferences->Java->installed jre's and add the jdk, and check it.
I'm trying to build a maven application, but I get an error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project helloworld: Compilation failure
[ERROR] D:...\Spark-test\java-getting-started\src\main\java\Main.java:[73,35] error: lambda expressions are not supported in -source 1.5
It's a heroku example java project, and in the system.properties file the java version is set: java.runtime.version=1.8
The specific lines are these:
get("/login", (request, response) -> {
System.out.println("request: " + request);
return "Hello World From Spark";
});
I don't understand where would be the problem, or where is set the source to java 1.5
Try adding this to your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Somehow maven tries to compile against java 1.5, which did not have lambdas yet (only since 1.8). How are you starting the build? Maven command line or an IDE?
Edit: alternative way, simply set these properties:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
source
I have installed Vagrant as a VM (single node) from this repository and then I installed maven inside so that I can create easily my HADOOP YARN jar files. When I am trying to build my jar mvn package I am getting an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project YarnTestClient: Compilation failure: Compilation failure:
[ERROR] /vagrant/openlab_ship_proto/YARN/src/main/java/ru/yandex/cern/yarntest/NMCallbackHandler.java:[16,25] generics are not supported in -source 1.3
[ERROR] (use -source 5 or higher to enable generics)
I have searched the whole internet but nothing solved my problem. Had anyone faced the same problem before? Thanks for your help.
Add this snippet to your pom.xml, if build tag didn't exist in pom.xml, maven would build java with source 1.3
<build>
<plugins>
<!-- compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project-sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
I ran into a strange problem..
I work on a project that use the ProcessBuilder Class.
On my local machine (Java6 and Java7 tested) I can easily mvn clean install & mvn assembly:single the project without any errors. Now I want to let the project build by travis-ci and ran into to following error
error: no suitable constructor found for ProcessBuilder(String)
full log file here..
but the Javadoc for ProcessBuilder show me that constructor.
My .travis.yml looks like this
language: java
jdk:
- oraclejdk7
- openjdk6
- openjdk7
after_success:
- mvn assembly:single
Any ideas why the build fails on travis-ci?
Thanks, F481
Edit:
Locally I'm using Maven 3, like travis-ci too (travis doc: "Travis Java builder will use Maven 3 to build it.")
My pom.xml: https://github.com/MultiServerControl/MineControl/blob/master/pom.xml
And the java code of the first error: this.processBuilder = new ProcessBuilder("");
The full class is available here
Edit2:
I specified a source and target version for the maven compilation like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Now the build is working for JDK7: https://travis-ci.org/MultiServerControl/MineControl/jobs/5963859
But I don't get the reason for that behavior.. and I want to build the project for JDK 5,6 too.
How can I do that?
I specified the version of the maven compiler plugin and the source and target version for the compilation like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Now the build is working! Much thanks to NilsH who pushed me in the right direction.