JavaFX11 and Intellij - java

I followed the instruction in this link
https://openjfx.io/openjfx-docs/#install-javafx
and when i run javafx sample i get this error
Error:(3, 26) java: cannot access javafx.application.Application
bad class file: C:\Program Files\Java\OpenJDK\javafx-sdk-11.0.1\lib\javafx.graphics.jar(javafx/application/Application.class)
class file has wrong version 54.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
and when i go to Project Structure > Project/Modules the JDK is set to JDK11
VM option:
--module-path C:\Program Files\Java\OpenJDK\javafx-sdk-11.0.1\lib --add-modules=javafx.controls,javafx.fxml
I tried to go to Settings > Build, Execution, Deployment > Compiler > Java Compiler
Project bytecode version was set to 8 and i changed it to 11 and the first error was gone but i got new error
Error:java: invalid target release: 11
I was searching on the internet and somebody said go to .idea\compiler.xml and set target to 11 but it's already set to 11 for me but i get the error

Go To File > Project Structure > Modules > Source
Set Language Level to 11 (if 11 not Available set to "X-Experimental Features")
Image

I have just encountered the error, could not find proper solution either, so I figured out myself.
Problem location: pom.xml - maven file
Sometimes issue can happen with different JavaFX entity, for instance with FXMLLoader or EventHandler:
java: cannot access javafx.fxml.FXMLLoader bad class file: ... class file has wrong version 55.0, should be 53.0
java: cannot access javafx.event.EventHandler bad class file: /Users/john/.m2/repository/org/openjfx/javafx-base/12/javafx-base-12-mac.jar!/javafx/event/EventHandler.class class file has wrong version 55.0, should be 53.0
Fixed version of pom.xml file:
<?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>
<groupId>hkr</groupId>
<artifactId>CommunicationTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
Incorrect (previous verison):
<?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>
<groupId>hkr</groupId>
<artifactId>CommunicationTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
The issue is in properties tag, the target version was below JDK version (9.0.1), which was causing in my case a problem of "class file has wrong version 55.0, should be 53.0".
I simply changed to target 9 instead of 1.8 and it got fixed.

Related

Could not find artifact com.test:1.1.3 in repository.jboss.org-public

I'm having an issue in Spring Project which i'm trying to use mvn sonar:sonar, but it's not working it's displaying this error:
Could not find artifact com.test:1.1.3 in repository.jboss.org-public (https://repository.jboss.org/nexus/content/groups/public) and
'parent.relativePath' points at wrong local POM # line 10, column 10
But i have already installed the dependency:
<parent>
<groupId>com.test</groupId>
<artifactId>jenkinspom</artifactId>
<version>1.1.3</version>
</parent>
What's could be the problem?
Youre artifact has the name com.test.jenkinsPom.
But you error message says just prints out the groupId com.test and the version.

java maven class not found exception

I built a server template in java and now i need to compile and run it using MAVEN.
this is my POM:
<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>bgu.spl</groupId>
<artifactId>spl-net</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
-<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>spl-net</name>
</project
When I run mvn compile it all works. but then i go to test it with: mvn exec:java - Dexec.mainClass=”bgu.spl.net.impl.BGRSServer.ReactorMain” - Dexec.args=”<port> <No of threads>” and it gives me a class not found exception. I looked in the target directory and this exact main was indeed there, it just refuses to run.
Turns out there was nothing wrong with my code. I failed to realize that in ubuntu, the command: mvn exec:java - Dexec.mainClass=”bgu.spl.net.impl.BGRSServer.ReactorMain” - Dexec.args=”<port> <No of threads>” simply doesn't work. the correct command would be: mvn exec:java - Dexec.mainClass=bgu.spl.net.impl.BGRSServer.ReactorMain - Dexec.args=<port> <No of threads>

Why am I getting sun.misc.Contended symbol cannot find error?

I've got a very simple program:
Test.java:
package com;
import sun.misc.Contended;
public class Test {
}
and 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>
<groupId>com</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
</project>
when I put mvn compile I've got:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project proj: Compilation failure
[ERROR] /home/john/Desktop/proj/src/main/java/com/Test.java: cannot find symbol
[ERROR] symbol: class Contended
[ERROR] location: package sun.misc
Why?
Because, sun.misc moved to jdk.internal.misc and they are private package to JDK.
... friend interfaces should be moved out of 'sun.misc'
and located in a truly private package. This is so that they are not
part of the proposed to be exported 'sun.misc' package.
You can use --add-exports and --add-opens to gain access to internal API.
In your case, you can add following in your pom.xml
<compilerArgs>
<arg>--add-exports</arg>
<arg>java.base/jdk.internal.misc=<<your.module>></arg>
</compilerArgs>
Please note, you need to change <<your.module>> to your actual module name.
Reference : - JEP-261:Module System

How to download source code from Maven Central for a project

I want to download the source code for the project XBee-api v9.3 from Maven Central so that I can modify the code for my application. I am using Netbeans and I have managed to produce a POM that validates and compiles successfully.
I have then run the command
mvn dependency:resources
from the same directory as the POM to force download of the source code.
I have a few problems:
When I look inside the project with Netbeans, I see the class files (which I think may actually be jars). When I open up any class, I only get the method headers, but not the source code.
When I open a class file, there is the option in the top right of the window to "Attach Sources...". When I select "Download", I get a message in the lower left of the window saying "Downloading source jar from known Maven Repositories for local repository file" but nothing seems to be happening.
When I open up the folder either with explorer or Netbeans files view, the folder is empty except for the POM. If I use Projects view in Netbeans, I can see a project structure and what appears to be the generated source files, but no source code.
I can't find answers on Google.
My questions are:
What am I doing wrong?
How do I download the source code?
Any help would be much appreciated.
<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.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<packaging>jar</packaging>
<version>0.9.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>A java library for communicating with XBee radios</description>
<url>https://github.com/andrewrapp/xbee-api/</url>
<licenses>
<license>
<name>GPL license, Version 3.0</name>
<url>https://www.gnu.org/licenses/gpl-3.0.html</url>
</license>
</licenses>
<developers>
<developer>
<name>Andrew Rapp</name>
<email>andrew.rapp+github.com#gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<!-- https://mvnrepository.com/artifact/com.rapplogic/xbee-api -->
<dependencies>
<dependency>
<groupId>com.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<version>0.9.3</version>
</dependency>
</dependencies>
</project>
The GitHub project page is here:
https://github.com/andrewrapp/xbee-api
(referenced in the POM under the url element)
...so you can just download the source from the Github page: https://github.com/andrewrapp/xbee-api/archive/master.zip

maven-compiler-plugin:3.1:compile(1 errors) in eclipse [duplicate]

This question already has answers here:
How to force maven update?
(26 answers)
Closed 6 years ago.
I want to learn java spring, so I choose Eclipse Mars2 Version and I want to build a java project using Maven. But I get errors
maven-compiler-plugin:3.1:compile(1 errors)
maven-compiler-plugin:3.1:testCompile(1 errors)
Then I check my maven and java path in my Windows 10 64 bit system variable.
I configured like this :
JAVA_HOME => C:\Program Files\Java\jdk1.8.0_71
M2_HOME => C:\apache-maven
MAVEN_HOME => C:\apache-maven
And in systen variabel path :
%JAVA_HOME%\bin
%M2_HOME%\bin
Everything is fine, I checked it by java -version and mvn-version
Also, I have installed mvn plugin in eclipse in install new software
to maven :
Name: m2e
Location: http://download.eclipse.org/technology/m2e/releases
But I still failed. The errors is still pop up.
Please advise. Thanks.
UPDATE
I test to build a project maven-archetype-quickstart version 1.1
execution default-compile, in Access/pom.xml
execution default-testCompile, in Access/pom.xml
UPDATE AGAIN
<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.tresnamuda</groupId>
<artifactId>access</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>access</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Eclipse detect error in first line which is :
project xmlns="http://maven.apache.org/POM/4.0.0" .....
also in line 8.
This is the complete error :
It seems like there is corruption in your local repository.
Please try:
Delete the local repository, if you use Windows, delete the folder C:\Users\your-user-name\.m2\repository
In Eclipse, right click on the project name and click Maven\Update project ... (or use hotkey ALT+F5)

Categories