JavaFX Eclipse suggestion to import not present - java

I am just starting with JavaFX and for some reason, Eclipse does not suggest to import JavaFX stuff so I have to type it in manually. Example: javafx.scene.Group I typed in Group as a type and it suggested other things such as javax.swing.GroupLayout.Group
image of suggestions
I'm not exactly sure, but I think maybe the fact that the JavaFX library is under Modulepath instead of Classpath has to do with it, but it only works if it is under Modulepath.
Help would be greatly appreciated, thanks!

I'm rewriting this answer, as #kleopatra pointed out it was inexact
For suggestions to work, you need to have JavaFX on your project's build path.
If you've created a plain Java project in Eclipse, with a module-info.java at it's source path root, then you need to add all the required jars to the module path:
JavaFX SDK should already be installed on your system, or download it from Gluon and unzip it
Right-click your Java project, got to Build Path -> Configure Build Path...
Go to Libraries tab, point to the Modulepath section
Click [Add External JARs...] button, pick all the jars from JavaFX SDK, hit [Apply and close]
Then suggestions should work as expected, and imports will be automatically inserted at the top of your java files, but they will appear in error the first time you import anything from a given library module, as this module must also be required in your module-info.java. You can do that automatically with a quick fix ("Add 'requires javafx.something' to module-info.java") when hovering the import.
Now there's a more straightforward way to create a JavaFX modular project in Eclipse, using Maven:
Create a new Maven Project
Check and pass the first wizard screen
Select archetype org.openjfx:javafx-archetype-fxml
On the next screen, you can select the JavaFX version of your choice (currently 13 by default)
After the wizard terminates, you've got a nice little project already setup with an application window and two FXML sample displays. You can start from there to build your own project.

Related

JavaFX imports and extends application not getting recognized

I'm having an issue with my JavaFX imports and the extends application portion of my main method.
I've tried cycling through all the SDK and programming level features on my IntelliJ and still no luck
Screenshot of the issue on IntelliJ
Sorry for the low-quality image but any help on this would be greatly appreciated
It seems the javafx library is not added to your classpath. This can be done by adding the folloging to your VM options:
--module-path [path\to\your\javafx\home\lib] --add-modules ALL-MODULE-PATH
where [path\to\your\javafx\home\lib] must point to the location where you downloaded javafx as it does not come with the jdk as of version 11: download
You can also add it as an external library in IntelliJ within the module settings (Dependencies).
If you hover the mouse over one of the red marks on the right-hand size, it should tell you what's wrong with the import. It seems that the IDE is complaining about all your javafx imports, but the other java imports are fine, so my guess is that you are using a JDK version that does not include JavaFX. If that is the case, you need to add it as an extrernal library to your project.
To do that, click on File->Project Structure, then select Libraries, click on the "+" icon, browse to the "lib" sub-folder of the JavaFX SDK folder, and add it.

IntelliJ: Why are my libraries not being recognized/downloaded?

IntelliJ newcomer here. I'm having some issues getting my project dependencies working:
So I have a project called ClearDialogue. It's an IDE for making branching dialogue for video games. It relies on my other project, Clear (ClearVG and ClearWindows) for creating its window and also rendering the UI. ClearDialogue also depends on LWJGL3 and a few other dependencies. The projects use Maven to manage its dependencies.
Clear is a project on my machine that I've set up in IntelliJ and successfully ran its demos. ClearDialogue however is where my trouble started; it relies on Clear to work, which is another project (not a JAR thats uploaded for it to fetch). So what I'm saying is: I need to be able to use another IntelliJ project as a library in ClearDialogue.
According to other similar questions, I can achieve this by referencing the other project in the pom file of the project that's referencing it. So I did that and it actually did appear in the "External Libraries" dropdown:
.
There are a few problems:
1) Despite Clear appearing in the External Libraries section, it's still not being recognized by the IDE as a library and when I try to build the project, errors like this are printed to the console:
.
2) It seems that Clear is the only library being downloaded despite LWJGL3 and other libraries being designated as dependencies in the pom file. They aren't being downloaded and aren't appearing in the External Libraries tab. That said, Clear itself uses some of the same libraries (LWJGL3) so is it that it's just making sure they aren't duplicated? Either way, the code itself is drawing red lines because it can't find the LWJGL3 libraries.
Does anyone know ways to fix these issues? Thanks in advance.
I managed to fix both of these problems myself.
To solve the first problem of using another project as a dependency, I was able to use the maven attributes of the projects to do so. I referenced Clear in ClearDialogue's pom file like this:
.
Then I opened the Maven view (View -> Tool Windows -> Maven) and added the pom files from Clear's own modules to the list along with the needed modules within the project itself:
.
After this I pressed the "Reimport all Maven Projects" button (the button in the picture above that looks like a refresh button) and rebuilt the project (Build -> Rebuild Project). This successfully downloaded all of my needed libraries and successfully added the local libraries from my own projects only available on the machine as well. With that I was able to successfully run to program as well.
As for the second half of my problem, I was able to find this answer from another question here on Stack Overflow, which coincidentally was how I was able to figure out how to add local dependencies as well.

What is the "right" way to add libraries on Netbeans?

I'm a using Netbeans 8.1 to code in Java, when I want to add an external library (such as XStream, JDateChooser, etc) I find the .jar online and I add it to my project through the right clicking in Libraries --> add JAR/Folder.
After this I write my code and everything works fine until I finish my project and I want to export it into a .jar with Clean and Build
I think this maybe because I give an absolute path to the libaray instead of a relative one but I'm not sure.
PS: The library that I'm having trouble with is XStream 1.4.7
All the libraries included should pack in a jar file after build. The simplest approach is to click right on your project, select Properties and The project properties. In the new window opened find Categories and Libraries. The in the right side you may see the button Add library/JAR. Probably it's the same way.
Also you can create a Maven project and import all the libraries through dependencies.

Adding external library in Android studio 0.3.6

So I am fairly new to Java, and I am trying to add this library to my project. The problem is that Android studio 0.3.6 doesn't have a simple way of doing that and all the answers I searched either reference an older version of Android Studio, or describe how to import an external project (source code, not jar file).
After reading a little, I got to the conclusion that manually adding the jar file would be the best way (manual copy/paste and gradle edits) but as I said, I'm fairly new to this technology and don't know where to place the file nor what lines I need to add to the gradle files.
Can someone help me?
UPDATE 1:
I finally made the IDE recognize the .jar file (I get autocomplete and class recognition). The new problem is that I get the following error when compiling: Gradle: package com.google.gson does not exist. Here are the steps I took to import the library:
Creat a folder called libs in the main directory (src/main/libs should be the result)
Copy the .jar file in that directory
add the following line to the dependencies section in the build.gradle file in your project: compile files('libs/gson-2.2.4.jar'). It should look something like this now:
dependencies {
compile 'com.android.support:support-v13:+'
compile files('libs/gson-2.2.4.jar')
}
Recompile the project (not sure if necessary, but I did it)
Right click on the libs folder and select "Add as Library"
Since the GSON library is available in MavenCentral, there's an easy way to add it that avoids having to download an archive file and save it in your project.
Go to Project Structure > Modules > Your module name > Dependencies and click on the + button to add a new dependency. Choose Maven dependency from the list:
You'll get a dialog box where you can enter search terms or the fully-qualified Maven coordinate string. Since GSON is a common library for Android developers to use, it's actually given in this dialog as an example, with the fully-qualified name. You can type it in:
Hit OK on both dialogs and you should be good to go.
With these Maven dependencies, the build system will automatically download the library and cache it if hasn't done so already; it takes care of that for you.
If you had a library that wasn't available on MavenCentral, you could save the archive in a libs folder in your project, and from that module dependencies dialog, add a File dependency instead of a Maven dependency to take care of it.
If you edit your build.gradle file by hand, you need to click on the "Sync Project with Gradle Files" button in the toolbar to force Android Studio to pick up the changes and update your project. If you go through the Project Structure dialog, that's unnecessary.
There are lots of conflicting answers to this issue in Stack Overflow because the functionality for this is in flux as the necessary features are implemented; it has been really broken before. These instructions should work properly for 0.3.6, and things will get a little easier in 0.3.7 and later.
I had the same issue. The new version of Android Studio (0.3.6) removed some necessary features to add an existing library to a project using the IDE. So you have to do this manually.
Adding the library into the build folder "<project>\App\build\libs\" will break the project on "menu > build > clear project / rebuild project".
Updated solution
My solution is to generate a new folder inside "<project>\<app name>\src\main\libs\" and add the library here. Now you have to change your "<project>\<app name>\build.gradle" by adding the following (my example shows the value for android-support library:
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
compile files('libs/gson-2.2.4.jar')
}
Now select the library in "project View" by right click and select "Add as library... > level > Global library". This will fix an import com.google.gson.Gson; issue.
Maybe you still cannot build. In this case you shall check you project module settings and see if there is an error for Gson dependency. I let Android Studio fix this issue by hitting a "small red bulb icon > add dependency" in the lower right corner of module settings dialog. Now it does not show me no errors anymore on build.
Now we have only one remaining problem: The project does lose the library reference on project close. So we have to add the library on open again. Maybe this is an issue of Android Studio 0.3.6. Mario filed a bug report.
BTW: I upvoted this question because I searched without success for a working solution in the internet. I think beginners will always fail to work with the Android developer tutorials of Google when they are forced to deal with the support library.
Update / Recommendation
Unfortunately I did not get AS 0.3.6 working properly. There are to many issues - at least when adding another module with different namespace. So I switched to the origin IDE: IntelliJ IDEA 12 community Edition. It's free and works for me. I did all the stuff in 2 hours which need days using broken Android Studio. I have no idea what forces Google to build its own IDE based on IntelliJ IDEA without additional benefits / noticeable features when the latter works like a charm.
Running Android Studio 0.4.0
Solved the problem of importing jar by
Project Structure > Modules > Dependencies > Add Files
Browse to the location of jar file and select it
For those like manual editing
Open app/build.gradle
dependencies {
compile files('src/main/libs/xxx.jar')
}
I posted the same to
importing jar libraries into android-studio
putting a duplicate here just in case you stumble into this post instead
Click on ProjectName->Libs folder.Paste that jar file into that folder.
Just refresh the project.You are done.
Using Android Studio 0.8.2, I had to do the following (supposing the library you're trying to add is called MyExternalLib):
In the "app/libs" folder on the hard disk, create a sub-folder "MyExternalLib", and copy the external library into that folder.
In the file "app/build.gradle", inside the block named "dependencies", add the line compile project('libs:MyExternalLib')
In the file "settings.gradle", add the line include ':app:libs:MyExternalLib'
Click the button "Sync Project with Gradle Files"
Create a new library module
It is good development practice to group functionality that you may reuse in other apps inside a library module. To create a library module inside the BuildSystemExample project:
Click File and select New Module.
On the window that appears, select Android Library and click Next.
Leave the default module name (lib) unchanged and click Next.
Select Blank Activity and click Next.
Type "LibActivity1" on the Activity Name field and click Finish.
The project now contains two modules, app and lib, with one activity in each module.
https://developer.android.com/sdk/installing/studio-build.html

In java, how do you import one project into another without having them in the same (Eclipse) workspace?

I've been a c++ programmer for 10 years, i'm used to just creating libraries and then linking to them from my existing project. However in java, i have 2 projects, one is my game engine, the other is the test environment that i would like to use, here is how it is structured:
com.logic.engine
com.logic.testapp
yet in my test app, i cannot do
import com.logic.engine.*;
it simply cannot find the reference.
How can I do this without having to copy and paste my engine into every program i write with it?
Package your engine as a jar, and add the jar to the classpath of the projects that use it.
In eclipse you can also declare that your test prgram depends on your game engine. The classes will then be available. Check in the build paths dialog available from the context menu in the project view.
In eclipse, right click on your test project in the Project Explorer and select Properties. In the "Java Build Path" section, go to the Projects tab and add your engine project.
You need to change the classpath to include the folder containing your engine.
java -cp /path/to/engine testapp
I just fired up Eclipse to check this out.
You should see a red wavy underline on import com.logic.engine.*; - mouse over this and it'll tell you that the import could not be resolved and offer you a number of so-called quick fixes. One of those should be Fix Project Setup - that will offer to fix things for you, in this case to add one project to the other's build path.

Categories