Can not work with MediaPlayer class, javafx.media is not found - javafx

I am trying to build a virtual piano app where i need the MediaPlayer class to play the notes, my project is a modular maven project with fxml, javafx 11.0.2 and java 14.
The problem that i can not import the MediaPlayer class, i tried to add requires javafx.media; to my module-info.java but it doesn't recognize it anyways.
Here is my module-info.java
module org.project {
requires javafx.controls;
requires javafx.fxml;
opens org.project to javafx.fxml;
exports org.project;
}
Also tried to download the library jar but it is empty.
Also tried to add a maven dependency in the pom.xml file as following:
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx.media -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx.media</artifactId>
<version>11.0.0-ea1</version>
<type>pom</type>
</dependency>
My pom.xml dependencies:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx.media -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx.media</artifactId>
<version>15</version>
<type>pom</type>
</dependency>
</dependencies>
and it shows that the repository is not found.

Note: This answer applies to other JavaFX modules such as fxml and web, as well.
javafx.media is a module, you need to require it in your module-info.java like you do for javafx.controls and javafx.fxml.
module org.project {
requires javafx.controls;
requires javafx.fxml;
requires javafx.media;
opens org.project to javafx.fxml;
exports org.project;
}
There may be other issues, but that is a likely one.
I don't recommend using the 11.0.0-ea1 release, there are later more stable versions. Latest stable release of JavaFX is 15 https://mvnrepository.com/artifact/org.openjfx/javafx-media/15, so I would advise you use that for all of your JavaFX dependencies.
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx.media -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>15</version>
<type>pom</type>
</dependency>
For later readers referring to this post, please use the most up to date non-early access release you can find using mvnrepository or a similar search tool.
tried to download the library jar but it is empty
Don't do this for JavaFX dependencies. JavaFX needs to include both native libraries and Java libraries. Just downloading Jar files may not work for you as you may be missing required stuff. Plus there may be transitive imports for libraries required which, again, just downloading a single jar won't pick up. You are already using a dependency hierarchy build tool in Maven, just configure and use it correctly and let it do its job.
Additionally, I think the javafx.media artifact was incorrectly named, configured and uploaded to maven central, which is why it only existed there as a 11.0.0-ea1 version. It should have been named javafx-media, which it is on subsequent uploads, so use the correct name for the artifact and then the most recent versions are there which include all the correct artifact data in the maven central repository.
My pom.xml dependencies
Your pom.xml dependencies mix JavaFX versions for different JavaFX dependencies. Don't do this, the different versions won't be compatible. Use the same version for all JavaFX dependencies.
i went to file> project structure > libraries > add library "java", opened the path where i installed my javafx > lib and chose javafx.media, then module-info.java could recognize it.
You should have your IDE re-import the updated maven project and auto-resolve the dependencies, not add the libraries manually to the IDE project.
For Idea, see:
How can I make IntelliJ IDEA update my dependencies from Maven?
For other IDEs the procedure will differ.
If you want to use WebView, or FXML or Controls, then use the sample module and dependency names here.
All steps for usage of these modules are the same as for the javafx.media module, only the names change.
Sample module names:
javafx.web
javafx.swing
javafx.fxml
javafx.media
javafx.controls
Sample dependency artifact names:
javafx-web
javafx-swing
javafx-fxml
javafx-media
javafx-controls

I found my mistake, i needed to add javafx.media from directory where i installed javafx, like this C:\Program Files\openjfx-14.0.2.1_windows-x64_bin-sdk\javafx-sdk-14.0.2.1\lib
to achieve that i needed to go to file > project structure
then i chose the javafx.media.jar
after doing this module-info.java could recognize the module.

Related

Not updated module version in Magnolia

What could be a reason for not updated module version in Magnolia 5.7
In Magnolia java project I have submodule with XML descriptor in META-INF/magnolia/mymodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "module.dtd" >
<module>
<name>mymodule</name>
<displayName>mymodule</displayName>
<description>my module</description>
<version>${project.version}</version>
<!-- <version>1.3</version> -->
<dependencies>
<dependency>
<name>core</name>
<version>5.7.4/*</version>
</dependency>
</dependencies>
</module>
When I rebuild the whole project with version changed in project maven pom.xml and deploy on a server I don't see an updated version in Magnolia's Author configuration console. I have to manually remove the old version node in the configuration console (remove JCR node) and then restart the server. After these steps, I can confirm the new version in the configuration console. Which is a pain if you have to deploy to several dev/stage/prod environments needless to say that I have no access to a public instance in a production environment.
The problem with not updated version sounds like not important, but I'm also not seeing new or renamed pages associated with this module. They appear only if I force to reload module by removing version.
One additional detail which may help identify the problem: I can delete version node in JCR, but can NOT delete the whole module node. I receive an error message "Level 1 and 2 nodes in config workspace cannot be unpublished".
What version do you see in the config:/modules/your_module/version before you delete it? Is it lower than version number of version you are trying to install? I would suspect that it's same or higher. Ie you are trying to reinstall same version or downgrade the version. Neither of those is supported hence it doesn't trigger the installation process. Or perhaps you are trying to move up from SNAPSHOT to full version for which there's no install delta either.
As for the warning you get when trying to delete those nodes, it is on purpose. You are not supposed to be deleting those nodes as a normal user since you could cause breakage of dependent (public) instances. Only as admin (via JCR Browser) you are allowed to delete, assuming you know what and why you are doing.

Can you run a JavaFX 13 application with a main method that calls launch (like in JavaFX 8)?

In JavaFX 8 one could just run a class that had a main method that called the static launch method on Application.class
Can this be done with JavaFX13? Right now i am doing it with the maven plugin and javafx:run but it is a bit annoying. Using NetBeans 11
have 3 dependencies on the project pom
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13.0.1</version>
</dependency>
Once i package my project into a JAR file, how do i run the main class that extends application from command line (without maven)?
You can run a Java 13 application with JavaFX from command line.
How to do so, depends on your project setup.
if your project is a java module as well, you should be able to define a module-info.java listing all you dependencies. The recommended way to run the application is to create a distinct JRE including your module and the required JavaFX modules. See here https://www.baeldung.com/jlink
if your project is not a java module on its own, you can make things work using the classpath and additional module directories.
I use the following JVM options to start my GUI application directly from my IDE using the JDK. The same options should also apply when you run your application from a jar file.
--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED
--module-path /opt/javafx-sdk-11.0.2/lib
--add-modules javafx.controls,javafx.fxml,javafx.web
This way, my code loaded via classpath is able to access javafx.scene package. For this to work I also had to configure the module path so java can find the JavaFX modules, and last but not least I had to add the modules from the JavaFX module path.
The jlink options for creating a custom JRE are similar.
You might have to use additional add-opens depending on what your application is doing.

Eclipse Luna maven-jar-plugin execution not covered by lifecycle

I have a maven java project (deploying to jboss, if that matters) that uses the maven-jar-plugin. This works fine using Eclipse Kepler. I'm now trying Luna (EE edition), and I'm now getting this error
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-jar-plugin:2.5:jar (execution: make-a-jar, phase: compile)
in all my child .pom files (the maven-jar-plugin is specified in the parent .pom file, but the error points to the block in the child .poms).
In the .pom viewer, if I click on the error message in the Overview tab, it gives me the option to "Discover new m2e connectors". Clicking on this brings up the "m2e Marketplace" dialog and appears to do a bunch of work, but then just shows me an empty list. If I click "Finish", it tries to calculate dependencies, and then gives me this error:
Operation details
Cannot complete the request. See the error log for details.
"m2e connector for mavenarchiver pom properties" will be ignored because a newer version is already installed.
So it appears to be that maybe the maven-jar-plugin depends on a particular version of mavenarchiver, but Eclipse Luna EE comes with a newer version. Is there a way to fix this problem, or do I just have to wait for a newer version of maven-jar-plugin to be released? (I'm currently using version 2.5 of maven-jar-plugin, which is the latest that I'm aware of.)
I had a similar problem when trying to import Hadoop project in Eclipse. The solution above works... but I got "tired" of changing some of the pom files, and thought that the change would bite me later. So, another solution is:
To avoid the messages in Eclipse regarding execution not covered by lifecycle, go to Windows -> Preferences -> Maven -> Errors/Warning and select Ignore for "Plugin execution not covered for Lifecycle.."
You can solve the problem when you change the phase of execution from compile to package (which is default lifecycle phase for jar goal).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin}</version>
<executions>
<execution>
<phase>package</phase> <!-- changed from compile to package -->
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

What Drools JARS are needed in a servet's WEB-INF\lib for jBPM?

I have ported a Tomcat servlet to run with JBoss 7.1 and am now trying to add jBPM support to it. I have run the jbpm-5.4.0.Final-installer-full.zip to get JBoss/jBPM installed with Kepler (I had to patch the installer to install Kepler). I then copied a line of code from the installer's "evaluation" sample and placed it in my servlet. That line of code is:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
After adding the necessary imports I got a clean build. I thought that I could then take the Drools run time files I found in the installer's .\runtime\lib and place them in my servlet's .\WEB-INF\lib. However, doing this caused me to get a "Class not found" exception when I tried to execute the KnowledgeBuilder line of code. It turns out that if I replace the JARs from the installer's .\runtime\lib with the JARS in drools-distribution-5.5.0.Final.zip (from http://www.jboss.org/drools/downloads) in my .\WEB-INF\lib I am able to execute KnowledgeBuilder line of code.
My questions are:
1) Why don't the JARs from the installer's .\runtime\lib work in the above?
2) Where can I find documentation on what all of these Drools JARs do and which ones are needed?
Thank you.
Al
If I were to list specific Jars here, the answer would only apply to a specific version of Drools. The best way to get the correct JARs is to use Maven to build your project. That will automatically import all of the JARs that are needed.
You will usually need dependencies for drools-core and drools-compiler. Those have their own transitive dependencies.
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
</dependency>
If you use Eclipse, then you can just create a pom.xml with those dependencies in it. Open it in the Maven pom editor and the "Effective POM" tab will show you all of the required dependencies.

Adobe Flex/AIR Maven integration

I am writing an Adobe AIR application that needs to build in a CI using maven and nexus. I tried to follow this article which is the most up to date article from the source, but I still don't understand these things:
Are the first and second pom.xml examples in the article in the same pom.xml file?
How do I get the Flex SDK dependencies on my CI?
It would be awesome if someone had a complete project setup and went through the whole thing.
This blog has some useful information on building Air applications with Maven 2.
As far as your numbered questions are concerned
Part 1: The two POMs in the tutorial are different. The first creates the swf package containing your application components. The second POM has a dependency on the swf package (note the dependency in the second POM for the artifactId Air in the first). The second POM defines processing to unpack the swf package (using the dependency plugin), then uses the exec plugin to invoke adt on the unpacked package contents.
The process described is therefore in two parts. The first POM packages the swf files so they are available in the repository. The second POM will retrieve any packages required from the Maven repository and invoke adt to compile them. So if you have multiple Air packages, the second POM can be modified to download the extra packages and compile them.
Part 2: Most of the dependencies you need are hosted in the Sonatype public repository, one notable exception seems to be the adt.jar. You can deploy the adt.jar to a Maven repository manager such as Nexus using the deploy plugin's deploy-file goal.
This would deploy the adt.jar to the repository with credentials matching the tutorial:
mvn deploy:deploy-file -Durl=http://path/to/repository -DrepositoryId=[some.id]
-Dfile=adt.jar -DgroupId=com.adobe.flex.compiler -DartifactId=adt
-Dversion=3.3.0.4852 -DgeneratePom=true -DgeneratePom.description="Flex ADT"
To reference the Nexus public repository, add a repository declaration to your settings.xml or pom.xml like this:
<repositories>
<repository>
<id>nexus-public</id>
<url>http://repository.sonatype.org/content/groups/public</url>
</repository>
</repositories>

Resources