Change to jdk 7 in eclipse(sts) - eclipse

How do I switch project from JDK 6 to 7, I know I am not using it because switch doesn't accept String.
In build path I have jre 7 in compiler settings I have 1.7 , everywhere and it still doesn't work. I use Spring Tool Suite(Eclipse based) latest version which officially supports Java 7.
And in project facets I also have 1.7. Why it has to be so bloody difficult.
And in .ini I have perfectly correct C:\Program Files\Java\jdk1.7.0\bin\javaw.exe
-startup
And I am sure my IDE supports 7 because whenever I create new project I have not syntax errors with String switch statement.
And my JAVA HOME set to JDK 1.7 :-)
UPDATE: The problem only happens with projects of Spring nature.
UPDATE 2: Happens with template Spring MVC project, Spring Hibernate template apparently works with Java 7.
Totally confused.

When I start a new Java project in Eclipse Indigo, eclipse tells me that the compiler compliance level 1.7 is not supported:
It is not possible to change that from inside eclipse, the properties dialog shows that:
So as a result, it is not possible to use the new switch statement with Strings in it:
See the "Eclipse Forums Post" for more information about the topic. It seems that it will come only with the next eclipse version.

In window / preferences / Installed JREs you need to have the JDK1.7 as the default set up. Additionally in Project / Properties Java Compiler it should be also set (or disable the project specific settings)
UPDATE :
In my .settings folder there is a file called org.eclipse.wst.common.project.facet.core.xml
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.4"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
and contains some rather suspicious values. Not sure it matters, but worth trying to close the project change it then reopen the project. If that doesnt help then search for the string 1.6 in all files in your project

Compare .classpath and .project files between your simple Java projects and Spring projects. Sometimes the Nature or other project setting can be set differently.

Related

Drools Eclipse Plugin ignores source level

I have installed the Drools Eclipse Plugin org.drools.eclipse 7.36.0.Final into my Eclipse 2020_03 running with a Oracle JDK 1.8.0_92. I have downloaded und unzipped drools-distribution-7.36.0.Final and added the binaries/ directory as Drools > Installed Drools Runtimes in the Eclipse Preferences.
As soon as I use any Java 1.5+ features (generics, foreach loops, closures, ...) I get error markers in the Rule Editor saying that there are syntax errors and those features require source level 1.5 (1.8 for closures).
My .drl files and the project itself seem to be fine, because I can compile and run via maven without errors. So it's not a blocking issue, but it's annoying that I cannot seem to get syntax checks for .drl files working properly in my IDE.
I have searched the internet and tried out all kinds of things:
I have set the JDT source levels in my project and workspace to 1.8
I have checked Installed JREs in the properties and only the one JDK 1.8.0_92 is listed
I have created a kmodule.xml file in /src/main/resources/META-INF/ with this content
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<configuration>
<property key="drools.dialect.java.compiler.lnglevel" value="1.8" />
<property key="drools.dialect.java.compiler" value="ECLIPSE" />
<property key="drools.compiler.lnglevel" value="1.8" />
</configuration>
<kbase name="rules">
<ksession name="codegen-rules"/>
</kbase>
</kmodule>
I have created a kie.properties.conf file in /src/main/resources/META-INF/ with this content:
drools.dialect.java.compiler.lnglevel=1.8
drools.dialect.java.compiler=ECLIPSE
drools.compiler.lnglevel=1.8
I have added the properties in the VM args section of my eclipse.ini file:
-Ddrools.dialect.java.compiler.lnglevel=1.8
-Ddrools.dialect.java.compiler=ECLIPSE
-Ddrools.compiler.lnglevel=1.8
But all of these do not seem to have any effect and it keeps giving me the same error markers.
How can I tell the Rule Editor that I want to enable Java 1.8 source level when syntax checking my .drl files?
I have run into this issue as well using the latest eclipse release and the latest drools release.
Using Eclipse 2019-03 and the Jboss Tools Integration Stack here does work. So either something broke in later eclipse releases or in the later drools versions. The integration stack uses 7.21.0.Final
I have not dug into what exactly broke but even if I did I don't know who I would report it to :(

Tomcat: Generated context-path is different for cloned application in Eclipse Juno

I've been trying to merge few different projects in to a single one in eclipse. In this attempt I've tried this following steps which causes the context path to be generated differently(incorrectly?).
Core-Problem:
Copied a dynamic web project (Maven) in eclipse and paste as a new project
(Cloned-duplicate)
Add the project to embedded Tomcat server in
eclipse.
Go to Tomcat Server project in eclipse and open server.xml
Generated < Context > tag contains the following
<Context docBase="DuplicateApp" path="App" reloadable="true" source="org.eclipse.jst.jee.server:DuplicateApp"/>
I would've expected both 'path' and 'docBase' to point to DuplicateApp, which is the name of the cloned app, however it is appearing incorrect. Is this even expected behavior?
Quite a bit of searching confirms my learning that both 'path & 'docbase' should point to the name of the web application/war file name.
Additional Information:
Eclipse Juno Java EE version installed
M2E plugin installed in Eclipse
Tomcat version 7
pom.xml did not override war name - cross checked.
After desperately refreshing to find no answer to my post, found answer to my own question after few additional hours of slogging!
There seems to be a property named 'Web Project Settings' which can be accessed via Project > properties > 'Web Project Settings' where context root can be changed. Not sure how this get populated or where it is retained just as yet. But atleast this solves my problem!

Java compiler level does not match the version of the installed Java project facet

I have created a New Dynamic Project under Eclipse Helios Version, where my JRE Version is set to 1.6.
I have added Maven capabilities to the Web Application by clicking on Configure → Convert to Maven Project.
After adding this, a build error appeared in the Eclipse Problems view:
Java compiler level does not match the version of the installed Java project facet.
Unknown Faceted Project Problem (Java Version Mismatch)
Please tell me how to resolve this error (I want to have my JRE version as 1.6 only).
If your project is not a Maven project, right-click on your project and choose Properties to open the Project Properties dialog.
There is a Project Facets item on the left, select it, look for the Java facet on the list, choose which version you want to use for the project and apply.
Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the source and target versions as 1.6 for maven-compiler-plugin. m2e uses these values to determine the project's Java compiler level. A snippet of the POM is shown below:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Alternatively, you can specify the maven.compiler.source and maven.compiler.target properties with values of 1.6, that happen to be the equivalent:
<properties>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>
TK Gospodinov answer is correct even for maven projects. Beware: I do use Maven. The pom was correct and still got this issue. I went to "Project Facets" and actually removed the Java selection which was pointing to 1.6 but my project is using 1.7. On the right in the "Runtimes" tab I had to check the jdk1.7 option. Nothing appeared on the left even after I hit "Apply". The issue went away though which is why I still think this answer is important of the specific "Project Facets" related issue. After you hit OK if you come back to "Project Facets" you will notice Java shows up as version 1.7 so you can now select it to make sure the project is "marked" as a Java project. I also needed to right click on the project and select Maven|Update Project.
I found #bigleftie's comment above very helpful:
"Four things must match
Project->Java Build Path->Libraries->JRE version
Project->Java Compiler-> Compiler Compliance Level
Project->Project Facets->Java->Version
(if using Maven) pom.xml - maven-compiler-plugin artefact source and target".
In my case, in the project properties, Java compiler, the JDK compliance was set to use the workspace settings, which were different from the java version for the project. I clicked on 'Configure Workspace Settings', and changed the workspace Compiler compliance level to what I wanted, and the problem was resolved.
I resolved this problem by setting the java version in Project Facet property of the project properties, Right click the project root folder -> Properties, search for Project Facets, and select compatible java version.
For reference -
I changed the configuration inside workspace/project/.setting/org.eclipse.wst.common.project.facet.core to :
installed facet="jst.web" version="2.5"
installed facet="jst.java" version="1.7"
Before changing config, remove project from IDE.
This worked for me.
I resolved it by Myproject--->java Resource---->libraries-->JRE System Libraries[java-1.6] click on this go to its "property" select "Classpath Container" change the Execution Environment to java-1.8(jdk1.8.0-35) (that is latest)
The Project Facet->Java should match whatever you have in the pom.xml for the maven-compiler-plugin artifact source and target.This is perfect.But if you donot have it here then you can also fix it by matching Java compiler version in Porject-Facets from the setting: Eclispe->Preferences->Java->Compiler
You can change project facet from
Project --> Properties --> Project Facet --> Java --> {required JDK version}
Right click the project and select properties
Click the java compiler from the left and change to your required version
Hope this helps
In Eclipse, right click on your project, go to Maven> Update projetc. Wait and the error will disappear. This is already configured correctly the version of Java for this project.
If using eclipse,
Under.settings click on org.eclipse.wst.common.project.facet.core.xml
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
</faceted-project>
Change the version to the correct version.

Where to put the User Library for Eclipse-Dali-Hibernate integration?

I am struggling with the configuration of the Eclipse Dali plugin and Hibernate. The version I'm using is as recommended:
Eclipse 3.6.1 (Helios SR1) IDE for Java EE Developers (including Dali 2.3)
JBoss Tools 3.2 (for the Hibernate Tools plugin)
When configuring the Java Persistence properties for my project, I created a user library named "Hibernate JPA" and included the following JARs:
hibernate-distribution-3.6.1.Final\hibernate3.jar
hibernate-distribution-3.6.1.Final\lib\jpa\hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-distribution-3.6.1.Final\lib\required\dom4j-1.6.1.jar
hibernate-distribution-3.6.1.Final\lib\required\slf4j-api-1.6.1.jar
hibernate-distribution-3.6.1.Final\lib\required\javassist-3.12.0.GA.jar
hibernate-distribution-3.6.1.Final\lib\required\commons-collections-3.1.jar
hibernate-distribution-3.6.1.Final\lib\required\antlr-2.7.6.jar
hibernate-distribution-3.6.1.Final\lib\required\jta-1.1.jar
As long as the hibernate-distribution-3.6.1.Final folder is outside of my project directory, everything works fine. However, if I put the Hibernate folder into the project directory, I get an error saying "Required class org.hibernate.SessionFactory does not exist in selected libraries":
The error text is wrong, the required class is definitely included in hibernate3.jar, and everything works as expected when I move the JARs outside of my project directory.
I have two questions about that:
I do not understand why the User Library behaves differently depending on whether the JARs are placed inside or outside of my project directory. Could anybody explain what's happening here?
I would like to have my project in SVN, including all the required libraries. Is there any way to configure Dali to accept User Libraries within the project directory?
Thank you very much.
I was having the same problem cos I forgot to add hibernate-jpa-2.0-api-1.0.0.Final.jar.
The only difference is that I'm using 3.5.1-Final cos 3.6.x seems not stable at the moment.
Actually, I'd prefer EclipseLink: everything works fine as a charm. I've wasted many hours with environment configuration :( Last time I've used Hibernate was years ago and looks like troubles to configure still are the same :(

Eclipse - How can I change a 'Project Facet' from Tomcat 6 to Tomcat 5.5?

(Eclipse 3.4, Ganymede)
I have an existing Dynamic Web Application project in Eclipse. When I created the project, I specified 'Default configuration for Apache Tomcat v6' under the 'Configuration' drop down.
It's a month or 2 down the line, and I would now like to change the configuration to Tomcat 'v5.5'. (This will be the version of Tomcat on the production server.)
I have tried the following steps (without success):
I selected Targeted Runtimes under the Project Properties
The Tomcat v5.5 option was disabled and The UI displayed this message:
If the runtime you want to select is not displayed or is disabled you may need to uninstall one or more of the currently installed project facets.
I then clicked on the Uninstall Facets... link.
Under the Runtimes tab, only Tomcat 6 displayed.
For Dynamic Web Module, I selected version 2.4 in place of 2.5.
Under the Runtimes tab, Tomcat 5.5 now displayed.
However, the UI now displayed this message:
Cannot change version of project facet Dynamic Web Module to 2.4.
The Finish button was disabled - so I reached a dead-end.
I CAN successfully create a NEW Project with a Tomcat v5.5 configuration. For some reason, though, it will not let me downgrade' an existing Project.
As a work-around, I created a new Project and copied the source files from the old Project. Nonetheless, the work-around was fairly painful and somewhat clumsy.
Can anyone explain how I can 'downgrade' the Project configuration from 'Tomcat 6' to 'Tomcat 5'? Or perhaps shed some light on why this happened?
Thanks
Pete
This is kind of hacking eclipse and you can get into trouble doing this but this should work:
Open the navigator view and find that there is a .settings folder under your project expand it and then open the file: org.eclipse.wst.common.project.facet.core.xml you should see a line that says:
<installed facet="jst.web" version="2.5"/>
Change that to 2.4 and save.
Just make sure that your project isn't using anything specific for 2.5 and you should be good.
Also check your web.xml has the correct configuration:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
This may be old but I tried and found the following in eclipse Galilio.
Open the navigator view and find that there is a .settings folder under your project expand it and then open the file: org.eclipse.wst.common.project.facet.core.Delete the content of this file and right click on the project and click on properties. Go to Project Facats in the popup window there you can click on runtime tabs and convert your project to the new facet you want.
if you are using Maven, then shutdown eclipse, then type >mvn eclipse:eclipse -Dwtpversion=2.0, and restart the eclipse.
Sorry it seems I can't post a comment without enough Rep so...
I think it's too difficult for eclipse to degrade safely to a lower standard because it can't really know if you've used something from the newer web standard. So if it just allows you do to that it could cause your program to fail on an older version.
You can always be backward compatible but not forwards compatible.
You can try to uncheck the facet, apply, change the value of the facet and check. It works for me in Eclipse Helios SR1.
So the main difference is that I do it with 'Dynamic Web Module'.
I hope it works for you too.
I saw the same thing, then I changed the web-app version value in the web.xml. Doing so could fix this for you.
If you are using maven you can generated the eclipse settings using the maven eclipse plugin.
For the jst.web version the Maven eclipse pluging takes into account the dependencies of the project. If you have a servlet api dependency defined :
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.32</version>
</dependency>
You jst.web parameter will be 6.0
<faceted-project>
...
<installed facet="jst.web" version="6.0"/>
...
</faceted-project>