Invalid flag -parameters in java 1.7 - java

I have the task to create the spring-boot application using Java 7.
So, as usual, I created a template on start.spring.io resource and open him via File -> New -> Project from Existing Sources...
When I run with jdk-8, everything works fine, but when I change JDK to version 1.7 (also I change java-version in pom.xml) I get a compilation error:
Error:java: invalid flag: -parameters
Screenshot:
Pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.exercise</groupId>
<artifactId>quadratic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>quadratic</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have no created any classes in this project.

-parameters is new feature introduced in java 1.8. The error is expected when it is used in java 1.7.
So please update java version to 1.8 if you want this feature.

Spring Boot 2.1 requires Java 8 as per the documentation:
Spring Boot 2.1.2.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.4.RELEASE or above is also required.
You must downgrade to Spring Boot 1.5 if you plan to use Java 7, as per the documentation:
Spring Boot 1.5.19.RELEASE requires Java 7 and Spring Framework 4.3.22.RELEASE or above. You can use Spring Boot with Java 6 with some additional configuration. See Section 85.11, “How to use Java 6” for more details.

Unsupported version of spring boot for Java 7. Pleaser downgrade and try

For me the JAVA_HOME was pointing to Java 1.7 although the java -version gave me Java 1.8 version.
So in CMD I just set the JAVA_HOME to 1.8 folder, and aligned also the PATH
like
set PATH=%JAVA_HOME%\bin:%PATH%

Related

Why you don't need to specify the version for some dependencies in Spring Boot project?

I'm learning about Spring Boot and I see that you don't need to specify the version for some dependencies, but you need to specify the version for other dependencies. Where does the version of this dependencies comes from?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dgs</groupId>
<artifactId>n-tier-and-jackson</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>n-tier-and-jackson</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<paypal.rest.easy.version>2.3.3-RELEASE</paypal.rest.easy.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>${paypal.rest.easy.version}</version>
</dependency>
...
For example in this code you don't need to specify the version for spring-boot-starter-jersey, but you need to specify the version for resteasy-spring-boot-starter. Where does the version for spring-boot-starter-jersey comes from? Thank you!
Dependencies versions are declared in the pom file that you have specified in the parent section of your pom file

How can I use my own parent.pom instead of the "spring-boot-starter-parent"?

I am new to Spring, Spring boot, and Spring boot starter.
For my different apps I use an own parent.pom for what the have in common. The parent.pom contains the version numbers as properties and dependencies that use the properties as version numbers.
When using my parent.pom maven states that I have to use the "spring-boot-starter-parent".
How can I use my own parent.pom instead of the "spring-boot-starter-parent"?
Meanwhile I changed the pom to this:
<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.websystique.springboot</groupId>
<artifactId>SpringBootRestApiExample</artifactId>
<version>1.0.0</version>
<name>SpringBootRestApiExample</name>
<parent>
<groupId>my</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Add typical dependencies for a web application -->
<!-- Adds Tomcat and Spring MVC, along others -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
But now I get this warning:
dependencies.dependency.scope' for org.springframework.boot:spring-boot-starter-parent:pom must be one of [provided, compile, runtime, test, system] but is 'import'. # line 27, column 1
You don't have to use spring-boot-starter-parent, it's just that it has an extensive dependencyManagement section that ensures all the Spring Boot dependencies you use in child projects have mutually compatible versions.
I typically declare spring-boot-starter-parent as the parent POM of my parent POM. This way, you get the best of both options.
It is also possible to import the spring-boot-starter-parent pom. So you can use your own pom as parent and you can use the dependency management from the spring boot pom.
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
...

Spring boot and elastic search unsupported version minimal compatible version

This is my pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
it.test
searchTest
0.0.1-SNAPSHOT
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M5</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Runtime, for Embedded Elasticsearch,
comment this if connect to external elastic search server-->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
When I start my project I have returned this stack trace:
[2017-12-15T13:36:15,670][WARN ][o.e.t.n.Netty4Transport ] [node1] exception caught on transport layer [org.elasticsearch.transport.netty4.NettyTcpChannel#7c08d374], closing connection
java.lang.IllegalStateException: Received message from unsupported version: [5.5.3] minimal compatible version is: [5.6.0]
at org.elasticsearch.transport.TcpTransport.ensureVersionCompatibility(TcpTransport.java:1428) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1375) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:64) ~[transport-netty4-6.1.0.jar:6.1.0]
What I have to change in my pom to solve this incompatibility?
Thanks
Change the transport version to be the same as your elasticsearch instance
What is the version of your ElasticSearch, Maybe you can try to add this property in your pom like this.
<properties>
<elasticsearch.version>6.1.0</elasticsearch.version>
</properties>
I always find the Spring data elasticsearch matrix table useful for figuring out what compatible version to use.
To change version of ES from to a compatible version use the Spring Boot dedicated module to specify dependency versions. Add elasticsearch.version into your pom properties
<properties>
...
<elasticsearch.version>1.7.2</elasticsearch.version>
...
</properties>
i too was getting similar error but got resolved, before which i like to highlight my spring boot starter parent version which is 1.5.9.RELEASE, secondly i was using spring-boot-starter-data-elasticsearch artifact alone for spring boot elastic search and other artifacts can be removed, finally the phenomenal issue which you are receiving with the elastic search application which you have installed, try to download this version https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-0 and try again....

spring boot : The import org.springframework.jdbc.core.JdbcTemplate cannot be resolved

I am having a hard time with one of my test programs which I am trying to write using springboot. When I try to import the JdbcTemplate class in the DAO layer I get an error : The import org.springframework.jdbc.core.JdbcTemplate cannot be resolved
I am not sure what I am missing, I have checked the dependency and they look fine to me. Below is my 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.vittles</groupId>
<artifactId>FoodFood</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FoodFood</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Attached is the error which I get in my java file
Also attach is the list of jar imports .
Can some one please let me know what I am doing wrong.
delete the folder ‘spring-jdbc’ from the maven repository:
%your_path%.m2\repository\org\springframework\spring-jdbc
open Eclipse -> right click on your project -> Maven -> Update project...
P.S. pom.xml should contain the jdbc dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
Looks your IDE is not updating the dependencies, try run as maven project - install.
I suggest you to use springboot, also.
I checked with your code but its fine, it have JdbcTemplate library class, seems like a simple error. try to update your project "right click project->maven->update project" or clean maven.

Error parsing lifecycle processing instructions when using spring-boot-starter-parent 1.4.3 with maven (works well on 1.4.2)

The following pom.xml does not work for 1.4.3.RELEASE of spring-boot-starter-parent, and it says "Error parsing lifecycle processing instructions". But once I change the version to 1.4.2, the issue is automatically resolved.
So my question is, is the 1.4.3 version incompatible with the pom schema definition?
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<packaging>war</packaging>
<artifactId>SpringCloudConfig</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
Deleting the entire .m2 folder or the specific jar files might help, in case there are corrupted jar files in your maven local repository. I solved the problem by removing the C:\Users\yourUserName\ .m2 folder. And then switch back to Eclipse Mars.(I was using Eclipse Neon when the problem occurs). Eclipse Mars is compatible with both the 1.4.2 and 1.4.3 version.
There is no need to delete entire repo. This is caused by corruption of some spring related jars. Just delete following folder from local m2 repo and update Maven project
.m2\repository\org\springframework
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
1.4.3.RELEASE
test
test
0.0.1-SNAPSHOT
test
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

Categories