Javafx eclipse не работает

Проект JavaFX в Eclipse не видит библиотеки из javafx-sdk

Но при попытке запуска получаю следующее сообщение:
Error: Unable to initialize main class application.Main
Caused by: java.lang.NoClassDefFoundError: Stage

Так же на строках импорта появляется сообщение:
The import javafx cannot be resolved

Попытался создать просто Java проект и импортировать в него необходимые библиотеки. Но и эта попытка завершилась неудачей.

Кто знает, в чем может быть причина?

Помощь в написании контрольных, курсовых и дипломных работ здесь.

JavaFX. Самое первое задание в JavaFX вместо Java. Не используя вспомогательных объектов
Всем привет, уважаемые форумчане! Мы работали на программировании в вузе на Java. Теперь дали.

Swing —> JavaFX, Переписать графический компонент в JavaFX
Всем привет! Только начал изучать Java. Пишу программу крестики-нолики(игра). Написал.

JavaFX и Eclipse первые шаги
Всем привет. Я извиняюсь за, возможно, глупый вопрос, но как собственно заставить работать JavaFX.

Проект JavaFX не корректно работает проект после запуска!
Народ, помогите разобраться. В общем ситуация такая. Есть проект на JavaFX в среде NetBeans.

Источник

JavaFX не распознается в Eclipse

JavaFX должен быть включен в последнюю версию JDK. Я использую 1.7 v 17. Импорт как:

не признала. Я бы предпочел не связываться с jar вручную.

Я слышал, что это была ошибка раньше, но она должна была быть исправлена. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7166330

у кого-нибудь есть ответ о том, как javafx можно распознать. Я не хочу иметь e (fx)clipe сделай это для меня, и я не хочу связывать банку. Насколько я понимаю, теперь он включен в последнюю версию jdk, поэтому я должен быть в состоянии сделать импорт, как указано выше, правильно?

3 ответов

JavaFX не находится ни на одном из путей классов по умолчанию в JDK7 — посмотрите, в какой версии была исправлена ошибка!

в JDK8 это исправлено, и JavaFX находится на пути ExtensionClasspath, но все же вы получите предупреждения от Eclipse, потому что материал на пути к классу расширения считается детализацией реализации — вы можете исправить это самостоятельно в JRE-Runtimes.

в чем ваша проблема с e(fx)clipse? Это исправит все ваши проблемы, независимо от того, развиваетесь ли вы против JDK7 или JDK8?

на Ubuntu 14.10 мне пришлось установить первый openjfx

затем я создал проект по умолчанию, используя e (fx)clipse и JRE по умолчанию (java-8-openjdk-amd64).

вы можете добавить «jfxrt.банку» вручную! Его в установленном JDK. Пример:

  • Windows XP:»С: программы \ файлы \ папку Java \ jdk1.7.0_17 \ JRE и \ Либ \ jfxrt.Джар«
  • Windows 7 (32 бита): «C: \ Program Files (x86) \ Java \ jdk1.7.0_17 \ jre \ lib \ jfxrt.Джар«
  • Windows 7 (64 бит): «C: \ Program Files \ Java \ jdk1.7.0_17 \ jre \ lib \ jfxrt.Джар«

скопируйте файл jar и поместите это вложенная папка в проекте (например, / lib).

теперь добавьте » jfxrt.банку» в classpath. Нажмите правую кнопку мыши на проекте и выберите из свойств -> путь сборки Java -> библиотеки -> добавить банки из . и добавьте файл jar.

Читайте также:  Как починить скрипящую кровать

Источник

How do I import JavaFX into Eclipse?

I have the latest JDK (update 65), but Eclipse doesn’t even recognize JavaFX when I try to import it.

How do I fix this and import it?

3 Answers 3

Do these following steps:

  1. Open Eclipse -> Help -> Eclipse Marketplace
  2. Search for «javafx»
  3. You’ll see e(fx)eclipse, install it.
  4. After installation, restart eclipse
  5. Then create new project File > New > Project(don’t select Java project).
  6. Then Select JavaFX > JavaFX Project
  7. Then click Next, give project name and click Finish
  8. You’ll get «The import javafx cannot be resolved»
  9. Download JavaFX in here JavaFX
  10. Extract the folder and place it downloads folder (or anyplace)
  11. Then in eclipse right click the project and select properties
  12. Choose Java Build Path
  13. Then select Libraries tab (you’ll see tabs on the top)
  14. You’ll see Classpath > JavaFX SDK
  15. Click on Classpath, then click Add external JARs from the right.
  16. Then from the download JavaFX (placed in downloads folder or somewhere you’ve placed).
  17. Choose all the .jars file in Downloads/javafx-sdk-11.0.2/lib/(all .jar(s) file) and click open.
  18. Then click Apply and Apply and close.
  19. Then you won’t get red underlines or (error).
  20. Then right click on project > Run as > Run configuration
  21. Choose the arguments tab and type this in VM arguments.
  1. (Important) Then uncheck the box that says «Use the -XstartOnFirstThread. «
  2. Click Apply and Run.

After following these steps

  1. Go Help
  2. Go Eclipse MarketPlace
  3. Search e(fx)clipse
  4. Install it

you can import javafx and if you want to add on your project just follow:

Java Build Path -> Libraries -> Add Libraries -> JavaFx SDK

Follow the steps:

Go Eclipse MarketPlace.

Not the answer you’re looking for? Browse other questions tagged java eclipse javafx or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.18.40487

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Почему не работает JavaFX?

Я только учусь и сразу же возникли проблемы с JavaFX. Библиотеки я подключил! Всё установил, а всё ровно ошибка!
Main:

  • Вопрос задан более двух лет назад
  • 8436 просмотров

Разобрался) У себя в конфигураторе в поле VM options прописал следующее:

В общем, всё заработало))

У вас ошибка class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x7f1029bf) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x7f1029bf сообщает о том, что он не может что-то найти/подключить.

Так как в VM options у вас был указан —add-modules javafx.controls, но нет, например, javafx.fxml и javafx.graphics, предлагаю именно их и добавить (через запятую после —add-modules javafx.controls).

Я сам потратил некоторое время, но разобрался. Для себя в поле VM options прописал следующее:

Источник

How to add JavaFX runtime to Eclipse in Java 11?

I am getting the following error as Java 11 excluded the JavaFX as part of the latest version.

So how can I add JavaFX to Eclipse in Java 11? Thanks.

6 Answers 6

Following the getting started guide, these are the required steps to run JavaFX 11 from Eclipse.

Install Eclipse 2018-09 from here.

Install JDK 11 from here.

Add Java 11 as an installed JRE to Eclipse: Eclipse -> Window -> Preferences -> Java -> Installed JREs -> Add.

Читайте также:  Что делать если не работает сабвуфер

Download JavaFX 11 ea from here.

Create a User Library: Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New. Name it JavaFX11 and include the jars under the lib folder from JavaFX 11-ea.

Create a Java project. You don’t need to add a module-path class. Make sure that you select Java 11 and you add the JavaFX11 library to the project’s modulepath.

Add a package javafx11 and the main application class HelloFX :

Note that the editor shouldn’t complain about JavaFX classes, as we have included the user library.

Add runtime arguments. Edit the project’s run configuration, and add these VM arguments:

—module-path C:\Users \Downloads\javafx-sdk-11\lib —add-modules=javafx.controls

Finally, run the project. It should work fine.

I’d like to share my findings regarding launching a javafx 11 app. I’m talking about an existing legacy javafx app originally developed without modules (e.g. w/ Java 8).

The most interesting way IMO is Method #2b below, which requires the minimum of changes, i.e. it doesn’t need -module-path argument. I mention that I’m using maven, so cf. previous answers the first step is to add a dependency in your pom.xml towards javafx. E.g.:

In order to launch, I found several options:

1a) Launch using maven from command line

Configure in your pom.xml a section like:

After this, from a console window you can run mvn exec:java , and this should launch the application. Maven will take care of adding all the entries from classpath to module path. I remind the CTRL + ALT + T shortcut in Eclipse, that opens a terminal window directly in the IDE.

1b) Launch using maven, but as an Eclipse launch config

Right click on the project > Run As > Maven Build. . Then enter exec:java in the Goals text box. Advantage over the previous method: a bit more integrated to Eclipse. And easy debugging. You only need to relaunch the launch config in Debug mode and that’s it. May I remind that the Eclipse launch configs can be stored as .launch files directly in the project dir (repo), thus shareable/reusable by colleagues. Use the last tab, Common, in the Edit Configuration window.

2a) Launch using Eclipse and specifying -module-path using a variable

Right click on the main class > Run As > Java Application. The first time you click a new launch configuration is created; probably it won’t work, so you need to edit it (e.g. **Run button (w/ Play icon) in the toolbar > Run configurations > select the one corresponding to your class. Or CTRL + click on it after clicking on Play).

Then add this in Arguments > VM arguments:

So the trick here was to use the $ variable. Because otherwise you should have needed to write exactly the path towards the javafx jar, that are somewhere in your .m2 repo. Doing this would make the launch config not easily reusable by colleagues.

2b) Launch using Eclipse WITHOUT specifying -module-path

This is la piece de résistence, which I found by mistake, after about 5h of Java 11 & modules «fun». Your application can work out of the box, without touching -module-path . The javafx libs will of course still need to be in your classpath (but this is handled by mvn). The trick is (cf. this) that your main app SHOULD NOT extend Application (e.g. MyApplication below). If this is your case, then make a new class with a main() function that does e.g.:

Читайте также:  Настрой компьютера через bios

In my case (i.e. on Windows, having a default JDK 8 in the system), there is a known issue regarding launching javafx. The solution is to add the following VM arg: -Djava.library.path=C: . So actually for all 4 methods described above I needed to add this.

I had problems regarding FXMLLoader . It was not able to find the class.

I resolved this by changing the arguments showed above, to load all modules, not only javafx.controls :

As mentioned by @Cristian, creating a separate Main class, seems to do the trick, without any other arguments.

@José Pereda is perfectly right, everything works as it should. I have tested it with the Eclipse release 2018-12. So, after you download the IDE (https://www.eclipse.org/downloads/packages/release/2018-12/r/eclipse-ide-java-developers) and install the e(fx)clipse plugin, you should be able to create a «JavaFx Project» item in your workspace.

The next step is to delete the «JavaFX SDK» from the «Classpath» module (Properties -> Java Build Path -> Libraries) and add the Maven dependency in order to remove compile errors:

The last step is to add a VM argument to «Run Configuration» of your JavaFX class for starting the application (Run Configurations -> Arguments tab -> VM arguments):

and it should work after you run it. Of course, you should download the JavaFX SDK before that (https://gluonhq.com/products/javafx/), unzip it and use the path to «lib» folder in the aforementioned VM argument.

Using Carlao2005’s advice I was able to put together a complete guide for getting JavaFX to work in Eclipse now that JavaFX does not come with the Java SDK. This assumes you have Eclipse with the E(FX)clipse plug in set up and an installation of the JavaFX SDK. Note, it is important that the JavaFX SDK is installed in a location without spaces in the path so C:/Program Files is not a good choice.

Go through this step for each new Java FX project to be built. First, go to file > new > other and find the option for creating a new Java FX Project. Once the project is created you will notice it does not compile as Eclipse needs to know about the JavaFX libraries. Access the project properties and then find the Java build path. Select the Libraries tab and then module path. Then select the add library button and then select the User library option before pressing next.

On the window that appears, select new and name the library JavaFX13. Select add external jars and then find the lib folder of your JavaFX 13 installation directory and select all of the .jar folders then apply and close or finish on all windows.

If you attempt to run the project you will find it will not be able to find application.main. To fix this we have one last step. Right click main.java in Eclipse’s package explorer. Select run as > run configurations and then select the arguments tab. In the vm arguments add the following (where the module path points to your installation of the Java FX sdk):

That’s it, you should now be able to run the Java FX project and see a default window. If running on Mac OS de-select the option -XstartOnFirstThread argument when launching SWT if you experience problems getting a window to display.

Источник

Оцените статью