IntelliJ IDE how to add SDK - java

i downloaded the JavaFX SDK from here but when i try adding it to IntelliJ i get the error "The selected directory is not a valid home for JDK".
[Project Structure -> Platform Settings -> SDK's -> add]
But i cant find an JDK from JavaFX, maybe i'am understanding something wrong between JDK's and SDK's. But IntelliJ says "add SDK" but need's JDK, can i switch it anywhere in the setting's or as i said above am i understanding something wrong.
Thanks in advance
Edit: The solution's beneth worked fine, here's what i found in the mean time link

IntelliJ doesn't make it all that easy to use JavaFX. I find the most intuitive way is to do the following:
Add global libraries for the JavaFX modules you want to use. The easiest way is to use from Maven and search for org.openjfx then add the modules you want (e.g. controls and fxml for the basic IntelliJ generated JavaFX project).
Create a module-info.java file for your app that looks something like the code below.
module MyModule {
requires javafx.controls;
requires javafx.fxml;
exports mypackage;
}
This creates a dependency on the javafx modules and exports your package so that the javafx reflection code has access to it.
There is an alternative method where the dependencies are added to the command line of the app's runtime but I find the method above more straightforward.

First, make sure that the JavaFX plugin is enabled (bundled and default). Then, in a new project, press Ctrl + Alt + Shift + s => Libraries => + => Java. Here, find the JavaFX folder you downloaded, then locate the lib folder in the JavaFX folder. Click on that, and it shouldn't complain about it not being a valid home. Apply your changes then close the dialog.
Now, in the main menu, hover over Run then click Edit configurations. Under the applications tab, click Main (or whatever your file is called). Then, next to the Build and Run section, hover over Modify options => Add VM options, then, in the text area, write the file path, paste:
--module-path /path/to/javafx/sdk --add-modules javafx.controls,javafx.fxml
Make sure you replace /path/to/javafx/sdk with the path to the lib folder in your JavaFX folder. If a name of a folder contains spaces, surround the entire file path with quotes.. Apply your changes and close the dialog.
Now you're done! Go ahead, code your JavaFX stuff, then hit run. Voila!
Official Documentation: https://www.jetbrains.com/help/idea/javafx.html

Related

Android - failed to generate Javadoc with Android Studio Bumblebee

I'm trying to generate Javadoc using latest Android Studio via built in tool:
Tools=>Generate Javadoc...
Whatever I choose from a tool's parameters window there are a lot of errors thrown, regarding to the scope I choose it varies from 50 to 100 and all of them related to Android OS or Dalvik VM. Here are some of them:
error: package android.util does not exist
error: cannot find symbol ... symbol:class Context
error: package android.app does not exist
error: package dalvik.system does not exist
Target Android SDK is 31. Latest Java release installed. Did someone experienced the same issue? What am I doing wrong?
Thanks in advance.
First of all, sorry for my English (I use Google translation).
I just spent 5 days on this error and found a solution that works (for me...).
The latest versions of Android Studio (including Bumblebee) do not generate technical documentation correctly. Here is the procedure to generate it correctly.
In Android Studio, open the project.
First of all, identify all R imports and just replace R with * (example: import com.example.coah.*).
Start by following the classic javadoc generation process:
Tools > Generate JavaDoc
scope : Module
uncheck "Include JDK and library sources in -sourcepath"
Output directory : give the path to the folder that will receive the doc (create this folder beforehand outside the project folder)
Other command line arguments : -encoding utf8 -docencoding utf8 -charset utf8
Make OK. Normally documentation generation failed with "exit code 4".
In the output window, at the very top and on the very right (drag the horizontal scrollbar), click on
"#C:\Users\xxx\AppData\Local\Temp\javadoc_args" :
You get a preview of the contents of the file.
Copy the content and paste it into a text file.
Open the file.
It starts with "-classpath" followed by quotes and a list of file paths. The problem comes from the fact that in this list, the android.jar file is missing, which is normally found in:
C:\Users\xxx\AppData\Local\Android\Sdk\platforms\android-32\android.jar
Check the presence of this file in the user folder (replace xxx by the name of the user) : it may not be android-32 but android-30, or other. Once the right path has been found, it must be added to the classpath, in the first position, just after the quotes and without forgetting to add a ";" at the end to separate it from the next path. Please note that the "" must also be replaced by "/".
Save file.
Open a command window in admin mode and go to the project folder, src\app\main\java folder.
Still in the javadoc output window in Android Studio, copy the first complete command line (which generates the doc) and paste it into the command window, replacing just what is after # with the path to the file text that has just been created (which contains, among other things, the classpath).
It is possible that there are errors and warnings, but the doc is still generated.
Emds
Emds solution helped a lot over here, using it we can solve this problem more easily.
As they said here, main problem is android.jar file is not being included in classpath somehow. So to resolve this we can simply copy path of android.jar (with name too) and then generate a dependency in project for it.
To do this go to File -> Project Structure -> Dependencies
There click on + sign in "All Dependencies" section and select "Jar/AAR Dependency".
Then select "app" for module and in next screen enter android.jar path (path you copied before) and click OK.
Build gradle again and generate Javadoc. It should do the trick.

Missing JavaFX application class sample.Main

My JavaFx project is working properly in intellij idea. In edit configurations, I have chosen the main class as sample.Main and when clicking the run button of intellij idea, project works properly.
Then I have converted my JavaFX project to a .jar file using build artifacts. But when trying to run .jar by using java -jar project.jar, there is an error "Missing JavaFX application class sample.Main". I have used same class in both occasions. So why does it output error while running .jar?
Finally this worked for me.
File-->Project Structure-->Artifacts-->press + button -->Add JAR-->From modules with dependencies. Now there will apear interface called create JAR from modules. Choose your exact Main Class there. Choose option "copy to the output directory and link via manifest". Directory for META_INF/MANIFEST.MF usually takes to java directory. It is good if you choose resources directory. Then click OK. A new window will appear.Click Apply and OK.Now go to the tool bar and click Build-->Build Artifacts-->Build.You can find built artifacts under the "project compiler output path".If you don't know exact location for "project compiler output path",then go File-->Project Structure-->Project-->Project compiler output. At the end of the project compiler output path you can see "artifacts" folder.There you can find a folder which consists all built jars.Right click the folder and click the "Show in Files".You can go to the exact folder having your built jars easily. Then open the terminal there and run "java -jar project.jar".project must be replaced by your application name.

Proper way to configure IntelliJ to use source code for decompiled jar

I have been trying to figure this one out for a bit, not coming up with the right approach. I read through this question, which I'd already tried, but it's not working quite right.. using IntelliJ EAP 142.4675.3
What I am trying to do, is to debug a junit test using a jar (extending the Provider class) file I've placed into JAVA_HOME\jre\lib\ext. I want that jar to be debuggable as well.
The problem is, if I attach my source directory as the source for a jar, then, in a stack trace, when I click the named file (containing a method I wish to view), IntelliJ asks me to choose between two of the same file, presumably because it knows about the source (it's in a module in my project) and it's also been told about the source via the jar source path I added.
I tried adding the provider.jar to the project module dependencies tab, which caused intellij no end of grief. Reverted back to having it in jre\lib\ext, and, in the Platform Settings->SDKs->1.8->Sourcepath tab, I added the module sourcepath. This lets intellij step into the .java file for the jar, vs the .class file, but, when it does so, I now get a banner at the top of my code windows which says "Alternative source available for the class xxx" and there's a combobox at the RHS with the module name listed twice (in the latest EAP, it actually lists the module and the jar [same name as module, with .jar]). And, as mentioned earlier, the IDE asks which which (of the very same) file I wish to edit when I click a file in the stack trace.
Clearly, there is something not quite right.. what am I missing? I find it odd that the ide will not open the source code when stepping into the jar until I attach the code as above, but, when I do, it sees it twice.
So let's start from scratch:
File > New Project, choose "Java Module", fill the form:
Bypass the form asking about the kind of project (webapp etc) by clicking on "finish"
you now have a project with a src dir:
right click the 32910506 directory and choose "New" then "Directory" and create a new directory named lib.
drag and drop your 2 jars (sources and code) to this directory (I will use common-lang for this example), beware to copy, not move:
now right click on src, choose "New", "Java class", name it App:
right click your "code jar" and choose "Add as library":
in App type psvm then hit TAB to get a main and fill it like this:
right click on your "code jar" and choose "Open library settings":
click "+" and choose "Attach file or directory" and select your "sources jar":
Now if your Ctrl+click on random in App, you should end up to the method source:
Put a break point in the random method:
Now right click App, choose "Debug App.main()", you should end up to the previous breakpoint:
Used: idea 12.1.6 under linux

How to use a "custom jar" in IntelliJ IDEA?

I'm trying to set up IntelliJ IDEA -- tried 12 and 13 -- Mac to use a Java class included a jar file for my Java application.
I've set the jar as a module dependency by the following procedure
Start from the "project window";
Select my main Java module;
Use menu File | Project Structure;
In Project Settings, select Modules, and select my Java application as interested module in the middle window;
On the window to the right, select "Dependencies" tab, and press "+" and select "Jars or directories" and navigate to the jar file, add select it so the custom jar file is added as a new entry in the window, check the Export checkbox and set Scope pulldown set as "Compile";
Press OK.
However, after setting this, in a Java class file in my Java application, if I use a class defined in the custom jar file, it still prompts me "Cannot resolve symbol 'SomeClass'".
Any idea what I'm doing wrong and how to fix this?
Edit:
my settings:
BTW, the Libraries and Global libraries are both empty. I tried to set the two jars there (separately) and add them as dependencies for the Java app, and had no luck, so I deleted them from Libraries and Global libraries. The above setting is using add module dependency as files directly (without first registering them as libraries), which still does not work.
Putting everything in the default unnamed package solved the issue.

Eclipse - Source not found

I know this question has been asked many times before, but none of the proposed solutions resolve my issue (or I'm not implementing them correctly).
I'm developing a plugin for OpenFire, and when I set a breakpoint in my plugin source Eclipse reports "Source not found". The JAR is built separate from the build of the OpenFire server. I've tried adding the JAR and specifying the source code directory, but no dice.
Here's the process I'm following: When I hit my breakpoint I'm clicking "Edit Source Lookup Path", clicking "Add", Java Library, User Library, click User Libraries, adding my library (tried both "Add JARs" and "Add External JARs"), and then specifying the folder that contains the source code. I've also tried:
Adding the source by selecting "File System Directory" instead of "Java Library"
Adding it by selecting "Workspace Folder"
In the Project Explorer, adding the source for my plugin to the Java Build Path
In the Project Explorer, adding my JAR as a Library and specifying the Source attachment
Thanks in advance for any suggestions.
Personally, I have no good experience in Eclipse JDT, when adding a source folder at the time it hits a break point. What I always prefer to do, is adding the source folder before debugging:
Select Project/Properties/Libraries
Select your library and "edit..." the source attachment
Select either the corresponding source folder or the zip/jar containing the package
After that, you should be able to open the source files in the virtual "Referenced Libraries" folder (directly below the "JRE System Library" folder inside the project), or when opening a reference to a linked class file from within the JDT editor. If you are able to access the source, then you should also be able to at least stop at the break point and see the corresponding source.
Else, you will have to check again, if the source folder is really valid: The source folder or source archive must contain the folder with the name of the root package of the library (e.g. the default Java "src.zip" inside the JDK folder also includes a corresponding "java" folder at its root). When in doubt, extract the archive and select the parent folder of the package you are interested in - sometimes source archives might be a mess or incompatible to JDT.
If this has been assured and it still doesn't work, chances are, that your linked source folder does not correspond to the compiled version of the library. Usually JDT will handle such inconsistencies fine, but if you try to open a source file, that is entirely different than the corresponding class file, you will encounter problems. In this case I would suggest either downloading the correct source version of the library, or recompiling the library from the source, if all else fails.
If opening a referenced source file from withing the JDT editor does work fine, and you are still unable to open the source files when a break point is entered during debugging, then most likely the class files are missing the line numbers of the corresponding source file. Again, you will have to recompile the library from the source in this case.
Finally, it is also possible to overwrite the default source lookup by specifying source folders or archives in the source tab of the launch configuration. But you should normally not need to do this, when your build path is configured correctly. From the Eclipse Help:
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.
I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.
In order to prevent this from happening, I:
1. Clicked on the "Breakpoints" window at the bottom of the debugging
screen
2. Right clicked "NullPointerException"
3. Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.alt text
(source: SharpDetail.com)
And this another one as:
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java) files and informs you about this. Here is how to tell eclipse where to look. Go to
Window->Preferences->Java->Installed JREs,select the JRE you are using and click Edit.
There, select all of the jar files in the list you see and and click Source Attachment....
In the window that shows up, select the fille src.zip, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
C:\Program Files\Java\jdk1.7.0_07\src.zip.
Save all your changes (possibly restart eclipse) and you won't see that error again.
Well it turns out the solution was anticlimactic. When Balder's recommendations did not work I tried debugging one of the stock OpenFire plugins and it worked just fine. I then created a new plugin from scratch, and by doing nothing other than adding the source to the project (Right-click on the project -> New -> Source Folder) it also worked just fine. I have no idea why Eclipse refuses to see the source for my original plugin, but I moved all my code and libraries over to the new plugin and debugging is working as expected.
Many times you put jar files in eclipse IDE as referenced libraries when binary version of application was downloaded. Usually done so by configuring the build path. But the binary does not have the source files. You have Binary version and source version of application.
One simple way is to download the source libraries that you also use maven to build the project.
Keep somehwere, may be inside your project workspace.
Now while seeing the class file (from eclipse, jar exploded) you may see the source not found, fine.... there is a button below and click on that, a new window opens and there select add external folder.
Reference it to the src folder of the source you downloaded(not the binary one) and kept somewhere as said above and it will show the class details from that.
I fixed this issue with doing the following:
Click at the menu Window - Preferences - Debug - Step Filtering And check all the packages like the following image.
(Step Filtering)
Then, debug again your project and thats it.
Best regards,
In my case, I had a breakpoint in the class declaration. I mean in the next line.
public class GenerateInterface implements JavaCall {
So, the debugger stopped in that line and showed the following message:
Source not found
I think unconsciously activate the breakpoint in that line.

Categories