Меню

Intellij idea не работает import

Проблема с подключением JavaFX в intellij IDEA

Добрый день, Я новичок в программирование, дошёл до изучения JavaFX. Но возникли некоторые проблемы. IDEA не видит не пакетов, не классов, не методов JavaFX. По совместительству являюсь пользователем Ubuntu, операцию по установки в linux Java FX уже выполнил

JDK естественно установлена, пробовал создавать проект как через Java, так и через JavaFX — бесполезно. Скриншот прилагается Заранее спасибо

6 ответов 6

0. установи OpenJDK. Реально меньше проблем будет

в Idea в свой проект добавь внешнюю библиотеку:
Ctrl+Shift+Alt+S: Project Settings -> Libraries -> + -> <выбираешь install/pass/to/JavaFX/javafx-sdk-11.0.2/lib>

обязательно добавляешь VM Option:
Run -> Edit Configurations -> Application -> :

Configuration -> VM options: —module-path $ —add-modules=javafx.controls,javafx.fxml,javafx.base

где $ — это твой путь к библиотеке JavaFX (install/pass/to/JavaFX/javafx-sdk-11.0.2/lib)

либо прописываешь в Path Variables:
File -> Setings -> Appearance & Behavior -> Path Variables -> +:
Name = PATH_TO_FX, Value = install/pass/to/JavaFX/javafx-sdk-11.0.2/lib

  1. можно еще установить SceneBuilder: https://gluonhq.com/products/scene-builder/ , но это — по желанию

При использовании Maven:

Добавить в pom.xml:

com.example.App — класс, который extends Application

Проще действительно использовать maven или gradle, как указали в комментарии.

Пускай вы новичек, потратьте немного времени на их изучение — и это значительно упростит дальнейшее обучение и разработку. С помощью них не нужно устанавливать javaFX или другие зависимости отдельно, всё делается в конфигурационном файле в пару строк.

maven попроще, а gradle посложнее, но возможностей намного больше (для javafx с gradle используйте не просто зависимости, а плагины, гуглите «javafx gradle plugin»)

А в данном случае, насколько я помню разработку без чудесных maven/gradle, нужно открыть настройки проекта (ctrl-alt-shift-s) и в разделе libraries добавить установленный javafx

Если все таки решите делать через maven, то вот отличное руководство по запуску. Если не хотите использовать maven, то можно скачать библиотеку javaFX отсюда, а затем в подключить ее в структуре проекта intellij idea (не помню как точно, но визуально там все понятно).

Есть два варианта: 1) использовать maven и не париться 2) Качать openJFX (качать openJFX https://gluonhq.com/products/javafx/) и читать хелп https://openjfx.io/openjfx-docs/#install-javafx

Я бы лучше посоветовал разобраться с maven, благо ссылку на урок вам дали.

Если очень коротко: Idea-File-New-Project-Maven(выбираем JDK и снимаем галку с архитипа)- GroupID: javaFX, ArtifactID: sample Next — Finish.

Когда откроется проект нужно в файл POM.xml добавить

IDEA сама скачает зависимости. Ну а дальше вы вроде знаете

Источник

Import and export projects

Open a project (simple import)

This option imports the selected project to IntelliJ IDEA as is (opens it). If you want to set custom settings while importing the project (for example, select another SDK or choose the libraries that you want to import), refer to Create a project from existing sources.

Launch IntelliJ IDEA.

If the Welcome screen opens, click Open .

Otherwise, from the main menu, select File | Open .

In the dialog that opens, select the directory in which your sources, libraries, and other assets are located and click Open .

When you import or clone a project for the first time, IntelliJ IDEA analyzes it. If the IDE detects more than one configuration (for example, Eclipse and Gradle), it prompts you to select which configuration you want to use.

If the project that you are importing uses a build tool, such as Maven or Gradle, we recommend that you select the build tool configuration.

Select the necessary configuration and click OK .

The IDE pre-configures the project according to your choice. For example, if you select Gradle project , IntelliJ IDEA executes its build scripts, loads dependencies, and so on.

If you have been working with another project, select whether you want to open the new project in a new dialog or in the current one.

Читайте также:  Не работает ручка пвх окон

For instructions on how to get a project from version control, refer to Check out a project from a remote host (clone).

Import a project with settings

This section describes the functionality that is available out of the box. If you are using a framework plugin, refer to the corresponding documentation section.

Import a project from an external model

Use this type of import if your project comes from an external model and you want to import it as a whole. In this case, IntelliJ IDEA interprets the project files (for example, your Eclipse project will be migrated to IntelliJ IDEA).

Launch IntelliJ IDEA.

If the Welcome screen opens, press Ctrl+Shift+A , type project from existing sources , and click the Import project from existing sources action in the popup.

Otherwise, from the main menu, select File | New | Project from Existing Sources .

In the dialog that opens, select the directory in which your sources, libraries, and other assets are located and click Open .

Select the external model that your project uses:

Gradle or Android Gradle: select the necessary build tool and click Finish .

For Maven and Gradle projects, the IDE configures the settings automatically. You will be able to adjust them after the project is imported.

Create a project from existing sources

Use this type of import to create an IntelliJ IDEA project over the existing source code that is not necessarily an exported project.

Launch IntelliJ IDEA.

If the Welcome screen opens, press Ctrl+Shift+A , type project from existing sources , and click the Import project from existing sources action in the popup.

Otherwise, from the main menu, select File | New | Project from Existing Sources .

In the dialog that opens, select the directory in which your sources, libraries, and other assets are located and click Open .

Select the Create project from existing sources option and click Next .

Specify the name and location and select a format for the new project. It’s recommended that you use the directory-based format.

If you are importing the project to the same directory, the IDE asks you whether you want to overwrite it. If you click Yes , IntelliJ IDEA will overwrite the files in .idea directory and the .iml files, your source files will remain intact.

Select the directories that you want to use as source root directories (folders with your source code) and click Next .

Select the libraries that you want to add to the new project.

You can join several selected libraries or archives into a new library by clicking or split the selected library into two by clicking .

Review module structure: select the modules that you want to include in your project.

You can merge several modules into one by clicking or split the selected module into two by clicking .

Specify the SDK that you want to use.

If the necessary SDK is already defined in IntelliJ IDEA, select it from the list on the left. Otherwise, click and add a new SDK.

Enable support for the detected frameworks and technologies: select checkboxes next to the necessary items.

You can also specify how the files-indicators should be grouped: by type (by framework) or by directory (by location).

Export a project

You can save a project as a .zip archive or export it to Eclipse.

Save a project as a .zip file

From the main menu, select File | Export | Project to Zip File .

Читайте также:  Как настроить свой никон

In the dialog that opens, specify the path to which you want to save the .zip file with the project and click Save .

Your project will be saved to the specified location as a .zip archive.

Источник

Auto import

This page describes Java imports. For information on imports in Kotlin, refer to Packages and Imports.

If you’re using a class, a static method, or a static field that you haven’t imported yet, the IDE shows you a tooltip prompting to add a missing import statement so that you don’t have to add it manually. Press Alt+Enter to accept the suggestion.

If there’s more than one possible source of import, pressing Alt+Enter will open the list of suggestions.

To change the background color for import tooltip, press Ctrl+Alt+S and go to Editor | Color Scheme | General | Popups and Hints | Question hint .

Statically imported methods, classes, fields have different style in the editor.

Automatically add import statements

You can configure the IDE to automatically add import statements if there are no options to choose from.

In the Settings/Preferences dialog Ctrl+Alt+S , click Editor | General | Auto Import .

Select the Add unambiguous imports on the fly checkbox, and apply the changes.

When you are pasting blocks of code that contain references to classes or static methods and fields that are not yet imported, the IDE automatically inserts the missing import statements. If you want to change that, from the Insert imports on paste list, select Ask to confirm every insertion or Never to insert import statements manually.

Import packages instead of single classes

IntelliJ IDEA suggests to import single classes by default. You can change the settings to import entire packages instead.

In the Settings/Preferences dialog Ctrl+Alt+S , select Editor | Code Style | Java | Imports .

Clear the Use single class import checkbox, and apply the changes.

Disable import tooltips

When tooltips are disabled, unresolved references are underlined and marked with the red bulb icon . To view the list of suggestions, click this icon (or press Alt+Enter ) and select Import class .

Disable all tooltips

Hover the mouse over the inspection widget in the top-right corner of the editor, click , and disable the Show Auto-Import Tooltip option.

Disable tooltips for classes or static methods and fields

In the Settings/Preferences dialog Ctrl+Alt+S , click Editor | General | Auto Import .

Make sure the necessary options are selected for the Show auto-import tooltip for setting (both checkboxes, Classes and Static methods and fields , are enabled by default).

Disable wildcard imports

When the number of classes that IntelliJ IDEA has imported from the same package reaches the limit ( 5 by default), the IDE modifies the statements in order to import the entire package instead of importing several single classes from this package:

Disable wildcard imports to always import single classes

In the Settings/Preferences dialog Ctrl+Alt+S , select Editor | Code Style | Java | Imports .

Make sure that the Use single class import option is enabled.

In the Class count to use import with ‘*’ and Names count to use static import with ‘*’ fields, specify values that definitely exceed the number of classes in a package and the number of names in a class (for example, 999 ).

To replace an import statement with single class imports in a file without changing the settings, place the caret at the import statement, press Alt+Enter (or use the intention action icon), and select Replace with single class imports .

Читайте также:  Не могу настроить прокси сервер что делать

Disable auto import

If you want to completely disable auto-import, make sure that:

Exclude classes and packages from auto import

The list of import suggestions may include classes and packages that you don’t need. You can exclude redundant entries from automatic import so that the list of suggestions contains only relevant items.

The list of excluded classes and packages is common for auto-import and code completion.

In the Settings/Preferences dialog Ctrl+Alt+S , click Editor | Auto Import .

In the Exclude from auto-import and completion section, click Alt+Insert , and specify a class or a package that you want to exclude.

You can also select whether you want to exclude items from the current project or from all projects (globally).

Exclude a class or a package on the fly

Press Alt+Enter on a missing class to open the list of import suggestions.

Click the right arrow next to a package and select an item (a class or an entire package) that you want to exclude.

In the Exclude from auto-import and completion section of the Auto Import dialog, select whether you want to exclude items from the current project or from all projects, and apply the changes.

Optimize imports

The Optimize Imports feature helps you remove unused imports and organize import statements in the current file or in all files in a directory at once according to the rules specified in Settings/Preferences | Editor | Code Style | | Imports .

You can exclude specific files and folders from import optimization. For more information, refer to Exclude files from reformatting.

Optimize all imports

Select a file or a directory in the Project tool window ( View | Tool Windows | Project ).

Do any of the following:

From the main menu, select _Code | Optimize Imports (or press Ctrl+Alt+O ).

From the context menu, select Optimize Imports .

(If you’ve selected a directory) Choose whether you want to optimize imports in all files in the directory, or only in locally modified files (if your project is under version control), and click Run .

Optimize imports in a single file

Place the caret at the import statement and press Alt+Enter or use the icon.

Select Optimize imports .

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports , and click Run .

Optimize imports when committing changes to Git

If your project is under version control, you can instruct IntelliJ IDEA to optimize imports in modified files before committing them to VCS.

Press Ctrl+K or select Git | Commit from the main menu.

Click and in the Before commit area, select the Optimize imports checkbox.

Automatically optimize imports on save

You can configure the IDE to optimize imports in modified files automatically when your changes are saved.

In the Settings/Preferences dialog Ctrl+Alt+S , select Tools | Actions on Save .

Enable the Optimize imports option and apply the changes.

Optimize imports on the fly

When you create a class from a template with the Optimize imports on the fly option enabled, IntelliJ IDEA will optimize imports from this template only after you reopen the project.

You can also configure the IDE to automatically optimize imports. IntelliJ IDEA will remove or modify import statements according to the rules specified in Settings/Preferences | Editor | Code Style | | Imports as you work in the editor.

In the Settings/Preferences dialog Ctrl+Alt+S , click Editor | General | Auto Import .

Enable the Optimize imports on the fly option and apply the changes.

Источник

Adblock
detector