bootstrap class path not set in conjunction with -source 1.6 - classpath

I am upgrading my application from java 1.6 to 1.7. When I try to build using Maven 3.2.1, my build fails with below error msg:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project my-app5: Compilation failure: Compilation failure:
[ERROR] could not parse error message: warning: [options] bootstrap class path not set in conjunction with -source 1.6
I am using java 1.7 hotspot and previously I was using 1.6 jrockit. My application is multi module and few modules compile and build as usual, this module failed.
I have set java home properly and mvn --version shows below output:
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T23:07:52+05:30)
Maven home: C:\Users\me\Maven3\apache-maven-3.2.1-bin\apache-maven-3.2.1\bin\..
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\Program Files\jdk17051\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Am I missing anything?

I solved it using below configuration in my compiler plugin:
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
<compilerVersion>1.7</compilerVersion>
<source>1.7</source>
<target>1.7</target>
This will use the JDK which you have defined in your JAVA_HOME environment property.

Quote from this post:
Java 5.0 and 6 used to have poor support for compiling classes to
target older versions of Java. It always supported the previous
version, but often no more. Even if you could compile for previous
version, you had to be careful not to use functionality which did
exist in the previous versions.
You should either include -Xbootclasspath when using javac:
javac -Xbootclasspath:/path/to/jdk6/rt.jar -target 1.6 -source 1.6 Main.java
or compile using -target 1.7 (or higher of course):
javac -target 1.7 -source 1.7 Main.java
or use javac of jdk 6:
/path/to/jdk6/bin/javac Main.java

Related

How to import netty to eclipse without pom errors?

I want to learn the source code of netty, and I import the source code of netty from github, I use maven to import these code but there are some pom errors here when I import the project:
I searched the Internet but I can't get any useful information.So I have nothing to do but to ask for help.
ps,
I attempt to follow the steps here:
and the solution is :
Set up Eclipse with M2E and Java 7/8
Ensure to use the 64-bit version of Eclipse.
Download os-maven-plugin and put it into /plugins (Eclipse 4.5) or /dropins (Eclipse 4.6) directory to work around the problem where m2e does not evaluate an extension specified in our pom.xml. (Unlike its name, it's both a Maven plugin and an Eclipse plugin.)
Import the project via the 'File → Import... → Existing Maven Projects' menu.
Netty project Maven pom.xml settings dictate use of Java SE 1.6, while implicitly using Java 7/8 (1.7/1.8) features if present. This may result in compilation errors in Eclipse. There are two ways to work around this problem:
Look in the 'Window → Preferences → Installed JRE' menu:
Make sure you have Java 7/8 installation available under 'Installed JRE'
Map this Java 7/8 installation onto Java 6: 'Installed JRE → Execution Environments → Java SE 1.6'
Alternatively, Java 7/8 JRE can be selected on per-project basis for each Netty module.
I follow these steps but I cant't solve this problem.
could you please help me to solve this problem? I look forward to your help.
my OS information:
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D102
my jdk information:
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
my eclipse information:
my maven information:
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /Users/mingxing/development/tools/apache-maven-3.5.0
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"

How to build dagger itself

The dagger project uses bazel.build system to build. I have installed bazel on Fedora, it runs and builds the project but apparently dagger has Java 1.8 code, and bazel targets java 7.
There is a build_def.bzl file and java target version is defined like so:
SOURCE_7_TARGET_7 = ["-source 1.7 -target 1.7"]
changing it to
SOURCE_7_TARGET_7 = ["-source 1.8 -target 1.8"]
does not help. Both master and rc11 branches fail to build because of the same error (java compiler complains about target version 1.7 not supporting lambda and method reference). There is no guide for building dagger on the wiki or project page and I'm unfamiliar with bazel. I wonder if something like retrolambda must be added to the build runtime path but it doesn't seem easy with bazel.
Sample output:
$> bazel build :all
INFO: Found 8 targets...
ERROR: /home/user/dagger/java/dagger/internal/codegen/BUILD:44:1: Building java/dagger/internal/codegen/libcodegen.jar (116 source files) failed: java failed: error executing command external/local_jdk/bin/java -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9-dev-r4023-2.jar -XX:+TieredCompilation '-XX:TieredStopAtLevel=1' -jar ... (remaining 2 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
java/dagger/internal/codegen/AbstractComponentWriter.java:612: error: method references are not supported in -source 1.7
(use -source 8 or higher to enable method references)
java/dagger/internal/codegen/AnnotationExpression.java:80: error: lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)
java/dagger/internal/codegen/AnnotationSpecs.java:41: error: method references are not supported in -source 1.7
(use -source 8 or higher to enable method references)
# Rest of output removed for brevity, the error above repeats for many more files.
I had wrong version of bazel installed. Building is as simple as running:
bazel build :all
I already had Oracle JDK 8 installed on my machine (Fedora) and downloaded this release of bazel (bazel-0.5.0-without-jdk-installer-linux-x86_64.sh).

Unable to create a maven project in eclipse

I am trying to create a maven project and its showing the below error
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
I have m2e plugin installed in my eclipse and the system variable is also set.
C:\Users\852346>mvn -v
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-14T01:40:2
7+05:30)
Maven home: D:\apache-maven-3.3.1
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jre7
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"**
But I am still getting the same error.
I found the answer, I forgot to add the proxy server I was using in settings.xml file in .m2/ directory.

Missing dependencies in Apache Crunch Scala build

I'm trying to build the Apache Crunch source code on my CentOS 7 machine, but am getting the following error in the crunch-spark project when I execute mvn package:
[ERROR] /home/bwatson/programming/git/crunch/crunch-spark/src/it/scala/org/apache/crunch/scrunch/spark/PageRankClassTest.scala:71: error: bad symbolic reference. A signature in PTypeH.class refers to term protobuf
[ERROR] in package com.google which is not available.
[ERROR] It may be completely missing from the current classpath, or the version on
[ERROR] the classpath might be incompatible with the version used when compiling PTypeH.class.
[ERROR] .map(line => { val urls = line.split("\\t"); (urls(0), urls(1)) })
[ERROR] ^
Other SO questions about similar errors (here and here) seem to involve PATH or version issues. I've been messing around but can't seem to resolve them. For completeness:
[bwatson#ben-pc crunch]$ scala -version
Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL
[bwatson#ben-pc crunch]$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
[bwatson#ben-pc crunch]$ mvn -version
Apache Maven 3.0.5 (Red Hat 3.0.5-16)
Maven home: /usr/share/maven
Java version: 1.8.0_31, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_31/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-123.20.1.el7.x86_64", arch: "amd64", family: "unix"
Any advice? I'm not really sure where Scala is looking for its dependencies, but I'd have thought that Maven would take care of it.
Unfortunately Different versions of Scala are binary incompatible. Currently by default Apache Spark uses Scala 2.10.4, not Scala 2.11. Apache Scrunch is dependent on Spark. Maven does not know anything about this so it can't help. It is necessary to make some modifications to Scrunch to get it to compile for Scala 2.11 / JDK 1.8. I am working on this at the moment, but I don't have a solution yet. However I get the error message you report if I compile Scala 2.10.4 with JDK 1.8, not Scala 2.11, so I don't think it is doing quite what you intend. The error seems be coming from the Protobuf compiler or jar but I don't know why that is.
When I solve it myself, I will report back!
It turns out the official documentation for Crunch was missing a Maven parameter. The issue was solved by building using:
mvn package -Dcrunch.platform=2

Why won't Eclipse compile my code in java 1.5?

I have installed Eclipse 3.5.2 and the JDK for Java 6.
Here's my installed JREs in Eclipse
alt text http://img806.imageshack.us/img806/3345/eclipsejres.jpg
I am trying to compile with an ant build file, part of which looks like this and specifies java 1.5:
<target name="compile" depends="build-common, init" description="Compile files. ">
<javac srcdir="${src_dir}" destdir="${build_dir}" debug="true" target="1.5" source="1.5">
<classpath path="${tomcat_home}/lib/servlet-api.jar;${tomcat_home}/lib/log4j-1.2.15.jar;/usr/local/lib/portlet-api-1.0.jar;." />
</javac>
</target>
But when I try to compile, the console window displays the following error:
compile:
[javac] Compiling 1 source file to H:\jephperro\portlets\build
[javac] javac: invalid target release: 1.5
[javac] Usage: javac <options> <source files>
[javac] where possible options include:
[javac] -g Generate all debugging info
[javac] -g:none Generate no debugging info
[javac] -g:{lines,vars,source} Generate only some debugging info
[javac] -nowarn Generate no warnings
[javac] -verbose ....
BUILD FAILED
H:\jephperro\portlets\CourseList-build.xml:25: Compile failed; see the compiler error output for details.
Total time: 531 milliseconds
What's my problem with Eclipse?
see the compiler error output for details.
You probably have a dependency on a library that was compiled using a later version of Java than your 1.5 JDK.
Actually, where is your 1.5 JDK? All I see is a JRE. My guess is that you just need to download a version 1.5 JDK and add that in Eclipse.
You could create a task in your ant build file that runs the equivalent of java -version so you'll get an idea of which Java compiler is being used by the ant that's started up by Eclipse.
Hint: Your default JRE is a 1.6 JRE. That's fine for running code, but not for compiling. Only a JDK contains the magic required by an external compile (such as done by ant). Eclipse gets around this by including an incremental Java compiler in its own code (more magic).
After years, I still don't fully understand how Eclipse, ant and the JDK interoperate, so maybe you need to do a little experimenting.
AFAIR Eclipse does not use its own internal Java compiler when an Ant file is run. Check your local paths and try to find out which javac is called by Ant.
The 'javac: invalid target release: 1.5' Compilation error is commonly caused by source/binary level incompatibility. Meaning you are trying to compile a source level of JDK 5 with a JDK 1.4 or less.
Eclipse uses a built-in Java compiler. The level actually followed by the compiler depends on the project settings. You can configure the Java level per project or set it as a default at a global level.
From the menu bar, select Window->Preferences. Select the Java->Compiler preference. Set the Compiler Compliance level to 5.0.
As Saifuddin and others mentioned this error is most likely the cause of not using the right Java compiler for the version you want. I notice in your installed JRE's there is a JDK located in DevsuiteHome_1, doesn't say what version. Maybe Ant is using that?
It is very easy to check. You are running ant within Eclipse. Ant has it's own configuration settings that can be different to your workspace. To check the version Ant is using when it runs follow these steps:
Run -> External Tools -> External Tools Configuration -> click on your ant build file (should be created if you ran it once already if not you could always create it here) -> select the JRE Tab -> Verify the runtime you are using