I have a JavaFX application that properly runs with Maven:
mvn compile
mvn exec:java # Launches the GUI
This is on Ubuntu, using openjdk-11-jdk, maven and openjfx Ubuntu packages.
I want to compile and run this application from the Eclipse IDE (eclipse installed with sudo snap install --classic eclipse). I have the m2e (Maven to Eclipse) plugin installed, and imported the project with File -> Import -> Maven -> Existing Maven Project. For non-JavaFX projects, the m2e plugin does everything needed to configure the project in Eclipse from Maven's pom.xml. Unfortunately, in my case, something is missing: typechecking works properly and finds the javafx.* classes, but when I try to run the application, I get the following error message in the console:
Error: JavaFX runtime components are missing, and are required to run this application
A workaround is to run the application as a Maven application (Run -> Run As -> Maven Build -> target=exec:java), but I find it less convenient and slower, so I'm looking for a way to get the application to run directly as a Java application in Eclipse.
I found the way to configure Eclipse manually (posted below as an answer), but I'm still wondering whether there's a better way, that would let Maven + m2e do the job completely, i.e. as much as possible configure everything from pom.xml and have everything "just work" in Eclipse.
The problem can be reproduced on a minimalist example, with this 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>jfxpl</groupId>
<artifactId>jfxpl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.2</version>
<configuration>
<mainClass>App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<mainClass>App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
And any application using JavaFX like:
import javafx.application.Application;
import javafx.stage.Stage;
public class App extends Application {
#Override
public void start(Stage stage) throws Exception {
System.out.println("Start!"); // Or real JavaFX stuff here obviously
}
public static void main(String[] args) {
Application.launch(args);
}
}
Since you have a Maven project, you could simply use the goals from the maven plugin you are using, and get Eclipse (via m2e) to run this for you, but you have to specify which are these goals, and which configuration you want to run.
Let's say you have this HelloFX sample.
Your pom will look like:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>org.openjfx.hellofx.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Note that I'm using the javafx-maven-plugin instead of the exec-maven-plugin, but you could use it as well. The former properly takes care of adding the JavaFX modules to the modular path, while the latter doesn't use modules at all.
If you were on a terminal, setting JDK 12 and running:
mvn clean javafx:run
will work as expected.
However, you want to run this from Eclipse, and not from a terminal, so you can create a new Maven Build configuration from Run -> Run Configurations... -> Maven Build:
Add clean javafx:run, and make sure the JRE is properly set (JDK 12 for instance). Press apply and close the dialog.
Now you can click the Run as green icon from the toolbar or from the context menu. A dialog will show up, and you could simply select the Maven Build option:
and press OK, it will run your goals as expected.
If you didn't have any Run configuration created, when selecting Maven Build will ask you to create one and provide the required goals. This means that Eclipse doesn't guess which of the possible goals from your pom you want to run when you click the run button.
Note that alternatively, you can press the drop down icon, and open a dialog that will show your custom configurations:
Pressing hellofx will run the specified goals.
Finally, you can still run your project as Java Application, without the benefits of a build tool like Maven, and you will have to add the VM arguments (which means you need to download the JavaFX SDK in the first place), as in your answer. Then you could run this other configuration (hellofx2 in my case) from the same drop down button.
Note that all of this is documented in detail here.
OpenJDK for linux doesnt come with the JAVAFX framework. you need to download it and install.
sudo apt-get install openjfx
After installing use following steps:
Set the SDK first
Step 1:
GOTO File -> Project Structure -> Modules -> Dependency >> + [on left-side of window] click + sign
Step 2 :
Run >> Edit Configurations
Step3: Add below parameter in VM config :
--module-path /path/to/JavaFX/lib --add-modules=javafx.controls
One solution is to configure Eclipse manually to add the required modules: Run -> Run configurations -> Java Application -> Arguments -> VM Arguments, add --module-path /path/to/JavaFX/lib --add-modules=javafx.controls:
If you need other modules, specify then as a comma-separated list like --add-modules javafx.controls,javafx.fxml.
This might be duplicate, did you try this
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<mainClass>your.main.class.which.extends.javafx.Application</mainClass>
</configuration>
</plugin>
Provided here: JavaFX Application with Maven in Eclipse
Also, there are docs for it, which probably correlate exactly to Java 11.
https://openjfx.io/openjfx-docs/
Here are the OpenJFX releases, provided from the docs.
https://gluonhq.com/products/javafx/
Also,
https://openjfx.io/openjfx-docs/images/ide/eclipse/modular/maven/eclipse05.png
Is a great image of the build through maven.
Related
Would really appreciate help here, please. I´m working on JavaFX application, first time. Tried to build standalone app. I´m not experienced, it´s first time what I see maven or other build tools. Before I build only small applications directly from Eclipse. I understand, that i have to pack other libraries (in maven as dependencies), "compile them", to one .jar file with my source codes. To farthest i got with maven and some .pom files. Tried many combinations of plugins and dependencies, but when i don´t fully understand what i´m doing, i´m always lost in it. Now I´m in state, that when run command in command promt (or build it as it in Eclipse with this goal)
mvn clean javafx:run
project is builded and my App is running. When I (in Eclipse) click on project right click -> Run As -> Maven Install (don´t know which command should I use in command prompt(javafx:install dont works)), It seems like my app compiled to .jar. But when i double click on that .jar, nothing happends. When I run it in command line (java UneccessaryFileCreator-0.0.1-SNAPSHOT.jar) i get error:
Error: Could not find or load main class UneccessaryFileCreator-0.0.1-SNAPSHOT.jar
Caused by: java.lang.ClassNotFoundException: UneccessaryFileCreator-0.0.1-SNAPSHOT.jar
Also I don´t see javafx dependencies in that .jar (when i browsing it in explorer) (but not sure, if i should see something there).
My project is here: https://github.com/JRulik/UneccessaryFileCreator
What is important i guess is structure of project:
https://i.stack.imgur.com/aay1Y.png
this .pom file:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>UneccessaryFileCreator</groupId>
<artifactId>UneccessaryFileCreator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>application.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
and maybe mine main class? :
package application;
/**
* Main Class to init JAVAFX
* #author Adminator
*
*/
public class Main {
/**
* Main method, using lunch metod on GUIManager.class from JavaFX to run main JavaFX thread
* (this is made to not need to pass parameters to JVM and due to run .jar only from command line) <-it was not helpful
* #param args
*/
public static void main(String[] args) {
GUIManager.main(args);
}
}
-> created "fake" Main because i read somewhere, that for this build purpose Main class should not extend some extern library class. So my GUIManager extends Application.
Please, would be really thankful for advice, spent last 2 days with this and still haven´t success. I choose maven because it looked like the easiest way. Using standalone plugins in command promt was too dificult for me. Would like to try another apps in JavaFX, but this releasing is really hell (or I´m also not brightest star on the sky)
I'm trying to use Javalin in my project and I can't seem to understand how to add the needed dependencies in order to work with Javalin without compliation errors.
The project i'm working on is not a Maven project, it is a simple Java project so it won't be downloaded automatically.
How do I add the dependencies and where?
I am using VSCode but can Switch to Intellij IDEA if needed.
Thanks.
At the risk of pointing you in a direction you may not want to go in... Use a dependency manager (Maven, Gradle, Ivy, or similar). Simple Java projects can be dependency-managed projects, too!
A basic Javalin project includes dozens of dependencies - and dependencies of those dependencies... You will probably have an unpleasant time attempting to handle them all manually, one-by-one.
If you use the Javalin bundle, that will take care of all of this for you.
To give you a sense of what I mean:
If you do decide to use a dependency manager, then your follow-up questions are well covered elsewhere. Or you can ask a follow-up, based on any problems you may encounter.
Update
Yeah but were doing it in a school project and were already half way through the project and now I need to add a Web Client and we don't want to change things all through the project, there's gotta be a way to add those dependencies without creating a new Maven project for it.
You can install Maven and run a command to download all the JARs to a directory.
This is (in my opinion) more work than just using Maven already built into all mainstream IDEs, but here are the steps:
Note: My set-up assumes Windows. You can adjust as needed for Linux or a different OS.
Download Maven - see here.
I downloaded the binary zip archive.
Set up Maven - see here.
Be sure to pay particular attention to the instructions regarding setting the JAVA_HOME environment variable pointing to your JDK installation or having the java executable on your PATH.
I installed my Maven here:
C:\maven\apache-maven-3.8.5
I tested it in a shell using the mvn -v command:
C:\maven\apache-maven-3.8.5\bin\mvn -v
Create a pom.xml file. Maven uses this as its instructions for what to download (and to what location).
In my case I created the POM here:
C:\maven\demo\pom.xml
Its contents are:
<?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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<groupId>org.andrewjames</groupId>
<artifactId>my-Javalin-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin-bundle</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies>
<build>
<finalName>my-Javalin-demo</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<silent>true</silent>
<outputDirectory>C:/maven/demo</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<name>my-Javalin-demo</name>
</project>
The maven.compiler sections assume I have Java 17 available. You may need to adjust to match your Java version.
The dependencies section is where the javalin-bundle is defined.
The execution section is the directive which causes all dependency JARs to be downloaded to the Maven local repository, and then copied to a new directory.
In my case the new directory will be created here:
C:\maven\demo\target\dependency
Open a CMD shell and cd to C:\maven\demo
At the command line, run the following command:
C:\maven\apache-maven-3.8.5\bin\mvn dependency:copy-dependencies
After that has completed, you will see approx. 100 JAR files in the C:\maven\demo\target\dependency directory.
I would like to use existing step definition classes coming from maven jar dependency.
My cucumber tests works if ran from Runner Class (with glue to packages) & mvn CLI. But the
problem is with IntelliJ Cucumber plugin for the steps which are coming from jar. In feature file steps that I am using from the jar are shown as "Undefined step reference:...". I am not even able to run directly from feature file.
Is there a way I can configure cucumber plugin to use stepdefinations from classloader/jar?
Posting the solution worked for Me:
Use IntelliJ 2020.1 +
In cucumber run configuration : select jar manifest for classpath
Deploy the Jar with source jar as well to Nexus as below
You can simple do this by adding maven-source-plugin plugin to your build
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
In other project add dependency and confirm source is downloaded from repo
File -> Project Structure -> Libraries -> Select the Artifact -> Sources , Make sure it's not in red.
Update IntelliJ to use latest version, for me IntelliJ version 2019 did not work but 2020.1 was able to find the step definitions.
PS: I use Java8 with Lambda exp and I can confirm it works.
Updating Intellij from version 2019.3 to 2022.2 solved the issue without changing anything else.
My project is in Java 8
I imported a Maven project and it used Java 1.5 even though I have 1.6 configured as my Eclipse default Preferences->Java->Installed JREs.
When I changed the Maven project to use the 1.6 JRE it still had the build errors left over from when the project was using Java 1.5 (I described these build errors earlier in: I have build errors with m2eclipse but not with maven2 on the command line - is my m2eclipse misconfigured?)
I'm going to delete the project and try again but I want to make sure this time that it uses Java 1.6 from the start to see if this eliminates the build problems.
How do I make sure the project uses Java 1.6 when I import it?
The m2eclipse plugin doesn't use Eclipse defaults, the m2eclipse plugin derives the settings from the POM. So if you want a Maven project to be configured to use Java 1.6 settings when imported under Eclipse, configure the maven-compiler-plugin appropriately, as I already suggested:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
If your project is already imported, update the project configuration (right-click on the project then Maven V Update Project Configuration).
I added this to my pom.xml below the project description and it worked:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
I wanted to add something to the answer already provided. maven-compiler-plugin by default will compile your project using Java 1.5 which is where m2e get's its information.
That's why you have to explicitly declare the maven-compiler-plugin in your project with something other then 1.5. Your effective pom.xml will implicitly use the default set in the maven-compiler-plugin pom.xml.
<project>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Your JRE was probably defined in run configuration. Follow these steps in Eclipse to change the build JRE.
1) Right click on the project and select Run As > Run Configurations
2) From Run Configurations window, select your project build configuration on the left panel. On the right, you will see various tabs: Main, JRE, Refresh, Source,...
3) Click on JRE tab, you should see something like this
4) By default, Work Default JRE (The JRE you select as default under Preferences->Java->Installed JREs) will be used. If you want to use another installed JRE, tick the Alternate JRE checkbox and select your preferred JRE from the dropdown.
Here is the root cause of java 1.5:
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target.
Reference : Apache Mavem Compiler Plugin
Following are the details:
Plain 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.pluralsight</groupId>
<artifactId>spring_sample</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Following plugin is taken from an expanded POM version(Effective POM),
This can be get by this command from the command line C:\mvn help:effective-pom I just put here a small snippet instead of an entire pom.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Even here you don't see where is the java version defined, lets dig more...
Download the plugin, Apache Maven Compiler Plugin » 3.1 as its available in jar and open it in any file compression tool like 7-zip
Traverse the jar and findout
plugin.xml
file inside folder
maven-compiler-plugin-3.1.jar\META-INF\maven\
Now you will see the following section in the file,
<configuration>
<basedir implementation="java.io.File" default-value="${basedir}"/>
<buildDirectory implementation="java.io.File" default-value="${project.build.directory}"/>
<classpathElements implementation="java.util.List" default-value="${project.testClasspathElements}"/>
<compileSourceRoots implementation="java.util.List" default-value="${project.testCompileSourceRoots}"/>
<compilerId implementation="java.lang.String" default-value="javac">${maven.compiler.compilerId}</compilerId>
<compilerReuseStrategy implementation="java.lang.String" default-value="${reuseCreated}">${maven.compiler.compilerReuseStrategy}</compilerReuseStrategy>
<compilerVersion implementation="java.lang.String">${maven.compiler.compilerVersion}</compilerVersion>
<debug implementation="boolean" default-value="true">${maven.compiler.debug}</debug>
<debuglevel implementation="java.lang.String">${maven.compiler.debuglevel}</debuglevel>
<encoding implementation="java.lang.String" default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<executable implementation="java.lang.String">${maven.compiler.executable}</executable>
<failOnError implementation="boolean" default-value="true">${maven.compiler.failOnError}</failOnError>
<forceJavacCompilerUse implementation="boolean" default-value="false">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>
<fork implementation="boolean" default-value="false">${maven.compiler.fork}</fork>
<generatedTestSourcesDirectory implementation="java.io.File" default-value="${project.build.directory}/generated-test-sources/test-annotations"/>
<maxmem implementation="java.lang.String">${maven.compiler.maxmem}</maxmem>
<meminitial implementation="java.lang.String">${maven.compiler.meminitial}</meminitial>
<mojoExecution implementation="org.apache.maven.plugin.MojoExecution">${mojoExecution}</mojoExecution>
<optimize implementation="boolean" default-value="false">${maven.compiler.optimize}</optimize>
<outputDirectory implementation="java.io.File" default-value="${project.build.testOutputDirectory}"/>
<showDeprecation implementation="boolean" default-value="false">${maven.compiler.showDeprecation}</showDeprecation>
<showWarnings implementation="boolean" default-value="false">${maven.compiler.showWarnings}</showWarnings>
<skip implementation="boolean">${maven.test.skip}</skip>
<skipMultiThreadWarning implementation="boolean" default-value="false">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<staleMillis implementation="int" default-value="0">${lastModGranularityMs}</staleMillis>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>
<testSource implementation="java.lang.String">${maven.compiler.testSource}</testSource>
<testTarget implementation="java.lang.String">${maven.compiler.testTarget}</testTarget>
<useIncrementalCompilation implementation="boolean" default-value="true">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>
<verbose implementation="boolean" default-value="false">${maven.compiler.verbose}</verbose>
<mavenSession implementation="org.apache.maven.execution.MavenSession" default-value="${session}"/>
<session implementation="org.apache.maven.execution.MavenSession" default-value="${session}"/>
</configuration>
Look at the above code and find out the following 2 lines
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>
Good luck.
Simplest solution in Springboot
I'll give you the simplest one if you use Springboot:
<properties>
<java.version>1.8</java.version>
</properties>
Then, right click on your Eclipse project: Maven > Update project > Update project configuration from pom.xml
That should do.
One more possible reason if you are using Tycho and Maven to build bundles, that you have wrong execution environment (Bundle-RequiredExecutionEnvironment) in the manifest file (manifest.mf) defined. For example:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Engine Plug-in
Bundle-SymbolicName: com.foo.bar
Bundle-Version: 4.6.5.qualifier
Bundle-Activator: com.foo.bar.Activator
Bundle-Vendor: Foobar Technologies Ltd.
Require-Bundle: org.eclipse.core.runtime,
org.jdom;bundle-version="1.0.0",
org.apache.commons.codec;bundle-version="1.3.0",
bcprov-ext;bundle-version="1.47.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.5
Export-Package: ...
...
Import-Package: ...
...
In my case everything else was ok. The compiler plugins (normal maven and tycho as well) were set correctly, still m2 generated old compliance level because of the manifest. I thought I share the experience.
Project specific settings
One more place where this can go wrong is in the project specific settings, in Eclipse.
project properties: click your project and one of the following:
Alt + Enter
Menu > Project > Properties
right click your project > project properties (last item in the menu)
click on "Java Compiler"
Uncheck "Enable project specific settings" (or change them all by hand).
Because of client requirements we had them enabled to keep our projects in 1.6. When it was needed to upgrade to 1.7, we had a hard time because we needed to change the java version all over the place:
project POM
Eclipse Workspace default
project specific settings
executing virtual machine (1.6 was used for everything)
In case anyone's wondering why Eclipse still puts a J2SE-1.5 library on the Java Build Path in a Maven project even if a Java version >= 9 is specified by the maven.compiler.release property (as of October 2020, that is Eclipse version 2020-09 including Maven version 3.6.3): Maven by default uses version 3.1 of the Maven compiler plugin, while the release property has been introduced only in version 3.6.
So don't forget to include a current version of the Maven compiler plugin in your pom.xml when using the release property:
<properties>
<maven.compiler.release>15</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
Or alternatively but possibly less prominent, specify the Java version directly in the plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>15</release>
</configuration>
</plugin>
</plugins>
</build>
This picks up Line's comment on the accepted answer which, had I seen it earlier, would have saved me another hour of searching.
I found that my issue was someone committed the file .project and .classpath that had references to Java1.5 as the default JRE.
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
By closing the project, removing the files, and then re-importing as a Maven project, I was able to properly set the project to use workspace JRE or the relevant jdk without it reverting back to 1.5 . Thus, avoid checking into your SVN the .project and .classpath files
Hope this helps others.
If you want to make sure that newly created projects or imported projects in Eclipse use another default java version than Java 1.5, you can change the configuration in the maven-compiler-plugin.
Go to the folder .m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1
Open maven-compiler-plugin-3.1.jar with a zip program.
Go to META-INF/maven and open the plugin.xml
In the following lines:
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>
change the default-value to 1.6 or 1.8 or whatever you like.
Save the file and make sure it is written back to the zip file.
From now on all new Maven projects use the java version you specified.
Information is from the following blog post: https://sandocean.wordpress.com/2019/03/22/directly-generating-maven-projects-in-eclipse-with-java-version-newer-than-1-5/
To change JDK's version, you can do:
1- Project > Properties
2- Go to Java Build Path
3- In Libraries, select JRE System ... and click on Edit
4- Choose your appropriate version and validate
I can't run the Maven Netbeans JavaFX example :
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) onproject mavenproject3:
Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e
switch. Re-run Maven using the -X switch to enable full debug logging.
My POM looks like 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.huw.almexoffice.client</groupId>
<artifactId>almex-office-client</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Almex Office Client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.huw.almexoffice.client.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Does anyone know why this is happening?
And if not, does anyone know how to get Maven running with the -e or the -X switch via Netbeans? I assume it is via a right click on the POM and then run goal then entering something in the textfield there.
This error would spring up arbitrarily and caused quite a bit of trouble though the code on my end was solid.
I did the following :
I closed it on netbeans.
Then open the project by clicking "Open Project", selecting my project and
Simply hit the run button in netbeans.
I would not build or clean build it. Hope that helps you out.
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up. In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.
I faced the same issue. When I tried to run the project from IDE, it was giving me same error. But when I tried running from the command prompt, the project was running fine. So it came to me that there should be some issue with the settings that makes the program to Run from IDE.
I solved the problem by changing some Project settings. I traced the error and came to the following part in my pom.xml file.
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
I went to my Project Properties > Actions Categories > Action: Run Project:
then I Set Properties for Run Project Action as follows:
runfx.args=-jar "${project.build.directory}/${project.build.finalName}.jar"
Then, I rebuild the project and I was able to Run the Project. As you can see, the IDE(Netbeans in my case), was not able to find 'runfx.args' which is set in Project Properties.
what's happening? you haven' shown much of the output to be able to decide. if you are using netbeans 7.4, try disabling Compile on Save.
to enable debug output, either run Custom > Goals... action from project popup or after running a regular build, click the Rerun with options action from the output's toolbar
I am a beginner in Maven - don't know much about it.
Carefully check on your input i.e. file path in my case.
After I have carefully check, my file path is wrong so it leads to this error.
After I fixed it, it works magically lol.
A solution which worked in my case is:
1. Go to the module having Main class.
2. Right click on pom.xml under this module.
3. Select "Run Maven" -> "UpdateSnapshots"
Had the same problem, I worked around it by changing
${java.home}/../bin/javafxpackager
to
${java.home}/bin/javafxpackager
Had the same problem after installing oracle jdk on Ubuntu 13.10 x64.
I've done the following steps, not sure which one helped. I think that at least 2 and 3 are necessary.
Deleted Netbeans 7.4 and reinstalled it from oracle's site.
Installed plugins for maven, ant and java that may be related to the project.
Deleted .nbproject folder - after that the project was considered a maven project.
Also, after that, I've found that the project runs, but exits with exit code 1 because I didn't supply the command line parameters for it. And the builder considers it is an error. So, look carefully for the output and see if the program actually starts.
Maven needs to be able to access various Maven repositories in order to download artifacts to the local repository. If your local system is accessing the Internet through a proxy host, you might need to explicitly specify the proxy settings for Maven by editing the Maven settings.xml file. Maven builds ignore the IDE proxy settings that are set in the Options window.
For many common cases, just passing -Djava.net.useSystemProxies=true to Maven should suffice to download artifacts through the system's configured proxy. NetBeans 7.1 will offer to configure this flag for you if it detects a possible proxy problem. https://netbeans.org/bugzilla/show_bug.cgi?id=194916 has discussion.
I solved this issue with right click on project -> Set as Main Project.
Netbeans needs to be able to index the maven repository. Allow it to do that and try again. It was giving me the same error and after it indexed the repository it ran like a charm
Try to run Maven from the command line or type "-X" in the text field - you can't break anything this way, at the worst, you'll get an error (I don't have Netbeans; in Eclipse, there is a checkbox "Debug" for this).
When running with debug output enabled, you should see the paths which the exec-maven-plugin plugin uses.
The next step would then be to copy the command into a command prompt or terminal and execute it manually to see if you get a useful error message there.
Restart Netbeans & it solved my problem.
Im new to java hibernate but i could solve this problem, this is how i did it :
I was working with hibernate and maven project.
First you have to put persistence.xml under project directory, then add jdbc manually.
Maven couldn't download my dependency so i added it manually.
In the persistence.xml in design jdbc connection add it manually ps: i work with netbeans good luck
For me, the clue was the "org.codehaus.mojo:exec-maven-plugin:1.2.1:exec".
The only place this was referenced was in the "Run project" action under Project Properties=>Actions.
When I changed this action to match the HelloFXMLWithMaven sample project (available in Netbeans 11.1):
"clean javafx:run"
then executing the Run goal was able to proceed.
Note, I also had to update the pom file's javafx-maven-plugin to also match the sample project but with the mainClass changed for my project.
Rohith H.Y Solved this problem
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up.
In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.