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

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

Related

Java failed to bootstrap path, eclipse, jdk-13

I’m trying to update my JavaFX project to be compatible with JRE 13 (until now it was set up to use JRE 1.8). I’m developing with Eclipse 2020-03, using a Mac.
The first big issue I’ve had to deal with is the migration from the included JavaFX libraries in JDK 1.8 to having to import JavaFX (14) as an external package for JDK 13.
The second issue is migration from using the classpath to using the modulepath. I’m new to the module path, so what I say about it may not make sense, but my current setup now is this:
modulepath:
<list of other .jar files>
JRE System Library [Java SE 13 [13.0.2]]
JavaFX 14
<list of .jar files I downloaded, including javafx-swt, javafx.base, javafx.controls, javafx.fxml, javafx.graphics, javafx.media, javafx.swing, javafx.web>
<I created a User Library from the above listed .jar’s>
Finally, all the compiler errors are now gone (I had to recompile some of the external .jar files I downloaded so there weren’t any split packages), but when I build and run the application class nothing happens.
Checking the Mac system console, the below output seems to reference why the app is not starting, but I checked he JDK path and the referenced java executable does exist.
com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.pid.java.40558): Failed to bootstrap path: path = /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin/java, error = 2: No such file or directory
What is happening here? If you need more info about my project config, comment and I can add details.

GWT hello world app does not compile and asks for 'com.google.gwt.core.Core'

I haven't done GWT development for a while and wanted to try again. In my Windows 10, I installed JDK 12 and Eclipse 2019-03. I installed GWT Eclipse Plugin (GWT 2.8.1).
From Eclipse, I created a hello world project this way:
Click on 'New GWT Application Project'
Project name: Gwt5, Package: com.foo, Use default SDK (GWT 2.8.1)
Click on 'GWT Compile Project'
I see this error:
Compiling module com.foo.Gwt5
[ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')
I didn't change my gwt.xml. I checked and "com.google.gwt.user.User" is there.
Any suggestion?
When language compliance level or JRE is set to higher than what GWT supports, this error occurs (The error message is not very helpful though).
As of May 2019, GWT supports only up to Java 8, and that is provided by JDK 1.8. For example, to make GWT work with Oracle's JDK, you need to download an older version of JDK (Java SE), than set both the Compiler compliance level and Installed JRE to:
Compiler compliance level: 1.8
JRE Home: C:\Program Files\Java\jdk1.8.0_202\

Eclipse's Ant needs jsch

I run ant script file in my Eclipse IDE. File contains command scp:
<scp file="myfile.txt" todir="user:password#somehost:/home/chuck"/>
This line causes error:
Cause: Could not load a dependent class com/jcraft/jsch/Logger
It is not enough to have Ant's optional JARs
Why my Eclipse's Ant does not have this class and where I can download requied library? How to know which library version is needed?
You can have a look here for JSCH http://www.jcraft.com/jsch/
There is a Download section where you can find a .jar (jsch-0.1.54.jar at time of writing).
Then you have to setup ANT buildpath to use this jar.

I couldn't build Jhipster sample app

I'm trying to run Jhipster sample app in my Eclipse kepler . I've downloaded the project from here and I've imported it as existing maven project but it couldn't be build . I got this exception :
The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files AccountResource.java
and many "Undefined CSS file" errors
how can I run this project in my Eclipse ?
Normally you should create your application using the yeoman generator. Install yeoman and execute yo jhipster from your command line.
a)For the java exception basically you need to remove the old version of java from your build path and add support for java 8.
You need to follow these steps
1) Right-click on project » Properties » Java Build Path
2) Select Libraries tab
3) Find the JRE System Library and remove it
4) Click Add Library... button at right side » Add the JRE System Library(Workspace default JRE)
Do not forget to set the Java jdk compiler compliance level to 1.8 (Preference -> Java -> compiler )
b) The jhipster site mentions about the configuration settings(css,javascript and html etc)for eclipse to avoid errors in eclipe. https://jhipster.github.io/configuring_ide_eclipse.html

Drools Java 7 support in Eclipse

I created a Drools project in Eclipse (Indigo) configured to use JRE 1.7. But I get an error pointing to my .drl file:
com/sample/DroolsTest$Message : Unsupported major.minor version 51.0
The com.sample.DroolsTest.Message class is imported by the .drl file. The Drools runtime was 5.2.1 (also tried with 5.3.0.Final).
Any help would be appreciated. Thanks.
This exception doesn't seem to have to do anything with Drools in particular, but is a generic Java error. It occurs if you try to execute a Java class with a JRE that is older than the JDK that was used to compile it. For example, if you compiled the class with a JDK7 and then tried to execute it with a JDK6, you would get this error.
Just to detail above answer and comment. I had both JRE6 and JRE7 installed, with JRE7 being the default. I had to do two things to remove the error from the drools sample project.
Set the JRE for the project to 1.6
Project properties->Java Build Path->Libraries. Remove JRE System Library 1.7 and Add Library->JRE System Library->Alternate JRE->JRE6
Set the compiler compliance level for the project at 1.6.
Project properties->Java Compiler->check Enable Project specific settings and set Compiler compliance level at 1.6.