I would like to run a simple media player made in Java from MATLAB, more precisely this one: https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/mediaplayerjava.htm
This code compiles without any problems and works, both when trying to run it in IntelliJ and when compiling with javac and running the .class file.
It compiles successfully under the same Java version as my MATLAB is using, so I am telling where the java-files are with javaaddpath(pwd). For some reason I get the error "Undefined function or variable 'MediaPlayer' while running the code provided in the link above, doing like this: test = MediaPlayer or test = MediaPlayer(); To be sure that everything is working I tried to compile and then run a simple java Hello World in MATLAB, which was working fine.
What could be the problem? If you have time, please help me out by compiling the code from the link above (2 files, press "Next Page for the second java file) and try to run it in MATLAB. I would be extremely thankful for any help!
Short answer:
The MediaPlayer is defined in package mediaplayer in your Java(FX) code:
package mediaplayer;
Therefore, the correct initialization would be:
test = mediaplayer.MediaPlayer();
Long answer:
From this point this question becomes really JavaFX specific and not about the trivial Matlab - Java interopability.
Problems:
JavaFX is bundled inside Java8 by default, and even Matlab R2016 is shipped with Java7, therefore the JavaFX package (javafx.*) will be not on the classpath of the JVM of Matlab, so you must ensure that JavaFX on the classpath of the JVM.
As soon as you manage to launch the Application (e.g. test = mediaplayer.MediaPlayer(); test.main({''});), it will block the Matlab thread. Even worse, when you close the window, the Application will still not exit and the Matlab thread remains blocked. This can be worked around by calling setImplicitExit(true) in the start method of the Application. This will force the Application to exit when all the Stages are closed, therefore the Matlab thread is not blocked anymore.
At this point the problem is that an Application cannot be started more than once. So if you have exited, you will be never able to start the same Application again.
What you can do to handle the last two points is to implement an "Application starter" in Java that runs on a separated thread and usable to execute JavaFX Applications.
Related
I have written a Java program that will execute an Alloy (.als) file. When I am using the commandline the program works perfectly but when I try to run it using NetBeans, this error is shown:
Exception in thread "main" Syntax error:
This module cannot be found.
It is not a built-in library module, and it cannot be found at "C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\util\integer.als".
What can I do?
Alloy is built & developed with Bndtools running in Eclipse. Trying to run it in Netbeans is just creating a huge amount of problems that you can avoid by taking the default route.
In Eclipse, all set up to immediately debug the main application is already done. It actually ensures resolves are handled inline instead of in another process so they are easier to debug. Then just debug it. Search for "built-in library module," and see what's happening there.
Even better, in Eclipse even the tiniest change you make to Java source code is immediately reflected in the runtime.
The quickest way I've found to fix this is to duplicate the .als files for the utilities in your file system.
Assuming your model (.als) file is in folder C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\, you'll need to create a util\ subdirectory in that folder and copy the source of the integer utility model (integer.als) into that subdirectory.
You can get the utility model files here.
Hello!
The goal I have is pretty simple: I want to create an executable .jar file which should be able to bring up a form (made using swing) and write the put-in information into a well structurized plain text file. Due to portability/mobility reasons I will have to run this on an Android phone.
Since Android unfortunately doesn't have native Java support and I am unable to code a real Android application myself, I tried to use a Java emulator. Unfortunately, it appears that a working Java Emulator is hard to find to begin with. JBED instantly crashes on my Medion X701. Netmite's Website, which also seems to offer a .jar to .apk converter, appears to be down. JBlend seems to have installed properly, but I do not know how to work with the program now that it presents me nothing but an empty screen with the caption "0 Java ME Application(s)". On the web, I could not find a proper manual. PhoneME's official website was Java.net, which is no longer active. But during my research, I could find an older Version of PhoneME which seems to be running well.
As a test, I created a simple jar file that shows a maximized JFrame. Unfortunately, it isn't able to run my simple executable Jar file on my phone. The main reason for that should be the aforementioned error, which implies that the interpreter there is probably Java version 1.7, since PhoneME's last release was in 2015. There are more error messages referring to an "unknown source", which I believe originate from the first error. I tried to recompile my jar file using Eclipse, by setting the Compiler compliance level to 1.7 and choosing the jre 1.7 before exporting my project. Unfortunately, this didn't change the error messages I got on PhoneME!
As my last attempt, I created a Startup.class file which does the very same thing as my jar file.
import javax.swing.*;
public class Startup {
public static void main(String[] args) {
JFrame fishForm = new JFrame("Questionnaire");
fishForm.setExtendedState(JFrame.MAXIMIZED_BOTH);
fishForm.setVisible(true);
}
}
I compiled it using the command prompt in order to make sure that it is indeed using java 1.7 as the target. This .class file, which ran fine on my computer, leads me into a different error: "Main class name missing.", followed by multiple lines of usage explaination. The command line PhoneME presents doesn't seem to allow me to post command operations myself, as pressing Enter on the virtual keyboard does nothing.
My Questions
Is it even possible to run a Java application on Android which relies on the GUI libraries of Swing, or am I wasting my time?
Is there a different, up-to-date Java emulator for Android which I could use? Or is there a working jar2apk converter somewhere out there?
If not, then there's probably a reason why Java emulators ceased to exist. Is there a much simpler solution for my initial problem which I am missing?
I'll await your ideas eagerly!
So I am doing an eclipse plugin for educational purposes.
My goal now is to have an additional java thread running , when the Run button is hit.
So, alongside with the normally launched programme , I want to have my own plugin code running (which I specified in the plugin).
I thought about trying to create a new java thread , running my code when I execute DebugUITools.launch(config, mode); .
But I am not sure how I would attach the thread to the launched process so that I could stop the thread too...
I also thought about creating java launch configuration for my plugin code, but it's probably impossible because as far as I can see, we need a Project for that.
So, are there any possibilities to programmatically attach new threads to a launched program? Or maybe create a second launch configuration out of plugin code, and launch it?
I hope I was able to explain my struggle to you.
Each Launch runs the code in a completely new JVM. You can't take a thread in the current JVM and move it to a different one.
A second launch configuration in your code would only end up launching yet another JVM which doesn't get you anywhere.
You would have the modify the existing launch configuration to add a jar containing your code and change the program entry point to point to your code so you can start your thread.
We use YAJSW (11.08) to wrap our java application as a service, but when switching to java 8, I noticed that if the application did not terminate gracefully, the .lck files generated by the logger, is not cleared.
We are in the process of switching to a new logger, but in the mean time I need a start up script to clear these .lck files.
I read here that YAJSW supports shell and groovy scritps, but the answer to this SO question answer claims it only supports groovy scripts.
As far as I can tell I need to indicate the STATE at which the script will be executed, so for me I assume that it's the START
state.
I have added this to my wrapper.conf:
wrapper.script.START=scripts/clean-up.bat
What am I missing or doing wrong? Is running scripts not available in the version I'm using? Or are shell scripts really not supported?
EDIT: Updated YAJSW to version 11.11 (latest) - still does not work
run the process from the console and see what error messages you get. I am running 11.11 with java 8 and I noticed that even though documentation specifies you want to say this:
wrapper.script.START=scripts/clean-up.bat
YAJSW already looks in the scripts directory by default, and you just have to make sure your script is in that directory. You can see the file not found error when running in the console.
My problem now is that I am getting a 'returned 1' error. I am beginning to doubt that YAJSW will run .bat files as I have made mine very simple just to test and it still fails.
I wrote a sample java agent that creates a "hello world" file in a specific place. I want it to run whenever any java applet is run (definitely including ones I didn't write myself.) How do I do that?
My agent works when I run it manually from the command line (as in, running another java file with the agent attached to it.) On the automatic front, I tried going into the java configuration panel -> Java -> View -> JRE Configuration Settings -> setting the optional arguments to attach my agent, but that doesn't seem to do the trick. I browse with FF to someplace that makes me run a java applet but no file is created.
I'm guessing I'm missing something basic here, because when I try to google this people all around various forums seem to answer it as if it's the most trivial thing: "just use -javaagent, read more about it in this (link)."
If it helps at all, this is the optional parameter I add in the configuration panel (which works when I use it manually):
-javaagent:C:\Users\admin\workspace\poc\bin\poc\myagent.jar
Update: I found out I can set an environment variable (JAVA_TOOL_OPTIONS) to -javaagent:(agentpath). Once again it works flawlessly with local java applications, but now when I browse over to a webpage with an applet, firefox auto-closes itself. IE declares the webpage broken. Chrome doesn't even display the applet. The agent itself at this point does nothing - it just has an empty premain method. Anyone?
Setting the environment variable JAVA_TOOLS_OPTIONS=-javagent:(path) is right.
My error was that I misconstructed the .jar file. Once I fixed that (simply used the jar.exe tool to make my .jar) it worked properly - locally and on all applets via firefox. Until then, that was what caused firefox to either hang or crash when encountering an applet.