java - Compiling and running with JavaFX 2.1 -
i trying simple use of javafx using simple set of lines of code got stackoverflow page (here). but, problem not code more fundamental in build , run process.
here code:
import javafx.scene.media.media; import javafx.scene.media.mediaplayer; . . . media medmsg = new media("msg.mp3"); mediaplayer medplmsg = new mediaplayer(medmsg); medplmsg.play(); at first couldn't compile @ all. figured out needed put -classpath c:\program files\oracle\javafx 2.1 sdk\lib\rt\jfxrt.jar on javac command line. (one obvious complex of questions here is: why isn't documented in obvious place (1) needed , (2) how figure out path javafx installation is?!)
but, when run code get:
exception in thread "main" java.lang.noclassdeffounderror: javafx/scene/media/media @ progtest.main(progtest.java:120) caused by: java.lang.classnotfoundexception: javafx.scene.media.media @ java.net.urlclassloader$1.run(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) ... 1 more what mean? looks doesn't know, @ runtime, how find class javafx.scene.media.media. but, %classpath% variable has "c:\program files\oracle\javafx 2.1 sdk\lib\rt\jfxrt.jar" in it.
any ideas? thank in advance!
this question duplicates compile javafx 2.0 manually.
this answer javafx 2 versions before release of oracle java 8. oracle javafx 8+, javafx runtime on classpath, don't need explicitly add when compiling or javafx running applications.
java includes javafx in jdk7u6 , above (for windows , linux) , jdk7u4 , above (for osx).
download , use jdk7u6+ , won't need specify jfxrt.jar file in classpath , of javafx related classpath issues should go away.
here link early binary build of jdk7u6.
for javafx 2.1 on windows need include jfxrt.jar lib in classpath compile (netbeans automatically if use it's javafx platform settings) , (if haven't packaged app correctly using javafxpackager or javafx ant tasks), @ runtime.
javafx 2.1 linux pre-release (in case using that). linux pre-release have include jfxrt.jar in classpath @ both compile , runtime if javafx runtime on linux not set correctly.
here example of command line compilation , execution of javafx program under windows.
launch editor:
c:\dev\test>notepad helloworld.java paste following code , save it:
import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.label; import javafx.stage.stage; public class helloworld extends application { public static void main(string[] args) { launch(args); } @override public void start(stage stage) { stage.setscene(new scene(new label("hello world"))); stage.show(); } } compile , run javafx 2.2:
c:\dev\test>javac -cp "\program files\oracle\javafx 2.2 runtime\lib\jfxrt.jar" helloworld.java c:\dev\test>java -cp ".;\program files\oracle\javafx 2.2 runtime\lib\jfxrt.jar" helloworld for oracle java 8+, explicit javafx classpath specifier not required:
c:\dev\test>javac helloworld.java c:\dev\test>java helloworld note rather compiling code , running it, package code javafxpackager or javafx ant tasks. these tasks embed launcher class packaged app detect version , location of javafx runtime don't need specify jfxrt.jar location unless want override default location platform.
Comments
Post a Comment