JavaFX source code not showing - intellij-idea

I downloaded the JavaFx source code from http://hg.openjdk.java.net/openjfx/2.2/master/rt/summary.
The name of the folder in the zip file is re-e71070b0e0c0.
I unzipped this and added the folder under Project Structure - Global Libraries in Idea, however it doesn't work. When I try to open a class it just shows field names and /* compiled code */. I couldn't find anything in the manual.

Much of the information in this answer is now outdated.
More up-to-date information on using JavaFX with Java 11+ in IntelliJ Idea, is available at:
openjfx.io in the section titled: "JavaFX and IntelliJ".
Though, the above-linked article is more focused on using JavaFX in IntelliJ rather than viewing JavaFX library source code in IntelliJ.
These instructions are only necessary for the JavaFX 2.x branch and will be obsoleted once JDK 8 is released.
After you have downloaded the source zip and extracted it, open Idea and follow these instructions:
Modify the source structure for your 1.7 SDK:
File | Project Structure | SDKs | Sourcepath
For each sub-project in the extracted zip, type Alt+Insert and add the respective source directory. For example rt-e71070b0e0c0\javafx-ui-charts\src, rt-e71070b0e0c0\javafx-ui-common\src, etc. Not all JavaFX 2.x source code is currently open sourced, so this will only add the open sourced portions.
Set the documentation lookup path:
File | Project Structure | SDKs | Documentation Paths
Specify a url Alt+S for the documentation: http://docs.oracle.com/javafx/2/api/
In your JavaFX application source, place your cursor over a JavaFX class usage, for instance LineChart:
Press Ctrl+B to open the source code file LineChart.java from your downloaded zip.
Press Shift+F1 to open documentation on the LineChart in a browser.
Press Ctrl+Q to get quick access to documentation from in the IDE.
Update Oct 16 2013
JDK 8 now includes JavaFX source files.
To tell Idea where JavaFX sources are:
Modify the source structure for your 1.8 SDK:
File | Project Structure | SDKs | Sourcepath
Press Alt+S to add the file javafx-src.zip, which is located in the root directory of the JDK 8 distribution.
Set the documentation lookup path:
File | Project Structure | SDKs | Documentation Paths
Specify a url Alt+S for the documentation: http://download.java.net/jdk8/jfxdocs.
The JDK 8 JavaFX documentation url will likely change when JDK 8 reaches General Availability release stage.
Step 3 above provides keyboard shortcuts to quickly access the JavaFX sources and documentation from your project.

(Since this is one of the Google hits for "javafx source code", I'll dump this anwer here too):
Quoting from this answer: For Java 8, the source of the public parts of JavaFX are actually laying right along in the JDK installation as a sibling of src.zip: javafx-src.zip - on the root of your normal JDK Java 8 installation.
Eclipse doesn't by default link them up when you add the JRE (or it finds it itself) - obviously a bug - so you'll have to do that yourself, by hitting Preferences -> Installed JREs. Find your JDK 8, hit Edit button. On the list JRE system libraries, expand the jfxrt.jar node, and link in the javafx-src.zip file.

I've faced this problem on Ubuntu 16.04 with JavaFX 8 (open-jfx package). The fix was to install the missing source package:
sudo apt install openjfx-source
IntellJ started showing JavaFX source code the second after the command finished executing.

Related

IntelliJ shows decompiled .class file instead of source code

I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.
This is what I see:
I am trying to open regular JDK source files.
The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij
The most detailed answer I've found so far is there as well.
Yet it doesn't work for me:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck
src.zip is not corrupt - I can open it via WinRAR
When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.
Everything else works/compiles properly.
My settings:
1. Get the source files
Make sure you have downloaded and installed the source files of the JDK.
I'm on Arch Linux and installed them with pacman -S openjdk8-src which put a src.zip into /usr/lib/jvm/java-8-openjdk/. We'll use that zip file in the next step.
To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src".
See this question on how to get the source files for your specific platform.
2. Point IntelliJ to the source files
In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:
3. Jump into the source
Select a JDK class, like Comparator, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.
I also have the same problem. The problem for my case is that Project SDK is set to 13 [Invalid]. After I can Project SDK to a valid SDK. My problem is solved.
I tried all the things mentioned at other places for this but at the end I was doing a silly mistake. Intellij was pointing to JDK 11 for which there was no source code (I had both the SDKs 8 & 11). I removed JDK 11 and pointed to JDK 8. JDK had the source code, thus now I can see the source code on ctrl click. Also, I had disabled the bytecode viewer and decompiler plugins. Hope this helps some one.
This also happens for large files - IDEA decides to decompile them instead if indexing sources, which can take ages.
If you're willing to accept the drawdown, adding the following in Help | Edit Custom Properties might fix the problem:
idea.max.intellisense.filesize=4096
On ubuntu there was java version “OpenJDK” when I changed to “Oracle Java”, the error went away and javadoc returned
I meet same problem and finally it gone after I copy JDK to another folder and change config in IntelliJ. I think maybe cause there is a space in path before, because it is installed under "Program Files" folder.
For downloading the source code of class files belong to jar you can use download source option present on top right corner in the de-compiled class file.
On my Windows 10, expand maven:
For me going to File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK and selecting Oracle OpenJDK solved the problem. Prior to that I had a different JDK selected and apparently it didn't include source code
If you are in a maven project make sure in the project structure all the complied folders are in the excluded section.
I suggest to use Linux Instead of windows. It's easy to find and download Java.
If you are using Linux, you can download SDKMAN
Install Java by SDKMAN
# find version
$ sdk list java
# download
$ sdk install java x.y.z-amzn
ctrl+alt+shift+s add JDK
Switch project JDK
If you are using maven , Right click on Project explorer -> choose Maven -> chick on "reload projects"
This did the trick for me:
Make sure you select the option "Project Files" (instead e.g. "Project").

IntelliJ can't detect openjdk source, even though it's listed in project sources [duplicate]

How can I step through JDK source code in IntelliJ IDEA 7 and see the debug info? I can currently hit breakpoints and step through the code, but the debug info is not available. This means I can't see the value of local variables.
I only want to step through the source code of one class, if that matters.
For what it's worth, it's the javax.swing.text.html.HTMLDocument class and I do have a copy of the corresponding .java file.
If you look in [File menu ->] Settings -> Debugger -> Stepping you will see a list "Do not step into these classes", probably with "java.*" listed there. Is that the case? You can turn that off there.
Apparently the debug information is not available. According to this thread:
Sadly the JDK classes have debug information for parameters and local variable stripped off.
Years ago I filed a request that Idea should deduce the necessary information from the source code (basically converting variable names to indexes into the methods local var):
Debugger: Show variable information when no debug info
Please vote/comment.
As a workaround you can re-compile the JDK from sources, but you need to exclude some classes which do not have all needed source code attached.
Interestingly, you can download the beta version of Java 6u18, which has debug information in it (in the DEBUG bundle).
UPDATE: IntelliJ IDEA 13+ version can provide local variables information without debug info.
Java classes which are part of the JDK are compiled without debug info for the size and performance reasons. If you want debug info in these classes, you'll either need to install a development version of the JDK where the classes are built with the debug info or rebuild the parts of JDK you want to debug from source with the debug info enabled and configure the new JDK with these versions of classes in jars.
This thread provides the instructions how to rebuild JDK classes in rt.jar from the source code with debugging information.
P.S. This question is not specific to IntelliJ IDEA.
Install the JDK
OSX download: https://developer.apple.com/downloads
Windows download: http://www.oracle.com/technetwork/java/javase/downloads
Add src.jar path
Go to: Project Structure (Project Settings) > Platform Settings > SDKs > Sourcepath
Add the path to src.jar
OSX example: /Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home
Windows example: C:\Program Files\Java\jdk1.7.0_03 (check Program (x86) for 32-bit)
Wait a long time for indexing!
Remove debugger filter
Go to: Settings > Debugger > Stepping
Uncheck the package(s) you want, e.g. javax.*
Along with the "Do not step into these classes" information, the src.jar should be configured. Right-click the project, select "Open Module Settings." Under Platform Settings, select "SDKs." Select the Java SDK version you're using. Select the Sourcepath tab, hit the "+" button, and add your src.jar from the JDK (or the separate source download for the OSX JDK). This will let you open JDK classes and step into them while debugging.
I did this on my Mac to get my Android source code but a similar approach should work for you.
File > Project Structure
Selected "SDKs" under Platform Settings.
Selected "Android SDK"
Selected "Sourcepath" tab
Pressed "+"
Browsed to location of my Java source code
you can find the source code from External Libraries --> rt.jar
setting - compiler - java Compiler - java options, you should check the option "generate debugging info", then, it will compile with debug info.

Cannot reference jdbc.SQLServerDriver in Eclipse (ClassNotFoundException)

I am trying to use the MSSQL driver for JDBC. I have followed the instructions on how to add an external JAR file to the Eclipse Windows IDE as follow:
- Download the installation from here http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx (Microsoft JDBC Driver 4.0 for SQL Server)
- Extract the zip to a file location I have extracted it here (c:\MsJDBCforSqlDriver)
- In Eclipse Package Explorer right click your project -> Build Path -> Configure Build Path -> Java Build Path -> Libraries Tab- Add External JAR file and then I browse to
"C:\MsJDBCforSqlDriver\sqljdbc_4.0\enu\sqljdbc4.jar"
- I then view the successful reference as in image below including SQLServerDriver.class
When I try to execute Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") I get a ClassNotFound Exception as below:
I tried all suggestions I could find on Google including setting the classpath in Windows Environment Variables.
Under the Run -> Run Configurations menu item you should find an entry for a Java application with the same name as the class that contains your main() method.
Have a look at the classpath tab. You should find your project listed under user entries. Expand it and see if the Microsoft JDBC Jar is listed.
The class path you use for compilation need not be the same as you choose for runtime, though Eclipse usually mirrors any changes to your build path to any launch configurations.
Your spelling and case for the package and class names look correct (Java is case-sensitive on names).
And yes, learning Java and Eclipse will take effort - Eclipse is quite different from other IDEs and it takes time to get to know it.
I found the answer here: http://code.google.com/p/android/issues/detail?id=27490
Seems like includes under Referenced Libraries is not available at runtime and I couldn't see how to change this in my version of Eclipse
"
Reported by fred...#mobileinteraction.se, Mar 22, 2012
Host OS: Windows 7 x64
SDK tools version: 17
Eclipse version: 3.7.2
ADT plug-in version:17.0.0v201203161636-291853
Platform targeted by your project: 2,2
Version of the platform running in the emulator: 2.2
STEPS TO REPRODUCE:
1. Create a project that uses external jars (in my case android-support-v4.jar ).
2. Added the android-support-v4.jar using Properties - Java Build Path - Add External Jar. Have the Activity extends from FragmentActivity.
3. Clean and run project
EXPECTED RESULTS: Application would run launching the FragmentActivity
OBSERVED RESULTS: Application crashes, android-support-v4.jar is placed within "References Libraries" and thus Android can't find it at runtime.
SOLUTION:
Manualy create a folder /libs within your project, copy the android-support-v4.jar to that folder and the ADT will place it under 'Android Dependencies' and it works.
This is the case for all external jars added using Properties - Java Build Path - Add External Jar.
"
Adding the JDBC driver of MS SQL Server to Eclipse:
Download the JDBC driver and uncompress it
Secondary click in the root of the Eclipse project and go to "Properties".
Now go to the section "Java Build Path - Libreries" y then click "Add External JARs".
Search the "sqljdbc.jar" file in the directory where you unpacked the downloaded driver, double click y finish pressing "ok".
I faced the problem and then solved the issue i.e. If You are using the Tomcat as a server for your Web application, the same Exception was coming as the Driver was unavailable to the project, later I put the jar file (sqljdbc4-2.0.jar) into the WEB-INF/lib folder then it was working

How to view JDK external documentation in IntelliJ IDEA?

The shortcut for this action is Shift+F1 but it is always grayed out even though I have pointed JDK documentation path to the docs folder (the docs folder is unzipped from jdk-7u2-apidocs.zip ).
Thanks
You need to specify the docs/api subdirectory of the unpacked documentation or use https://docs.oracle.com/javase/8/docs/api/ URL for the external documentation feature to work.
File -> Project Structure... then here :
I'm using 10.5.4. It was unclear to me from the docs or from resources online that you need to add this at Project Structure > SDK's > (Choose your SDK) > Documentation Paths > Specify URL.
For IntelliJ Idea:
Call "Project Structure" (Ctrl+Shift+Alt+S), go to "Platform Setting - SDKs", choose "Documentation Path" tab on the right, then add url of JavaDoc (http://docs.oracle.com/javase/7/docs/api/) to your project
You can add the external Javadocs API link as shown below:
Go to File > Project Structure...
Then select SDKs (under Platform Settings)
Go to Documentation Paths tab
Select Specify URL button and add the link for JDK 11 API docs (https://docs.oracle.com/en/java/javase/11/docs/api/)
I understand the question as follows:
You would like to see javadocs of classes that are not within JDK. I am a bit uncertain because CrazyCoder's reply is talking about JDK specific javadocs.
I am using Macos 10.8.4 and Intellij 11.1.5
The project I am working on is a mvn based project with many modules which have complex dependencies.
Let me take a concrete example to explain what I did, I am sure it can be reproduced for others: apache sshd
I downloaded the javadoc from maven central stored it stored it somewhere. In intellij I went to the module settings (shortcut F4) and the to Libraries in the sidebar. Maven pulls all dependencies automagically and I can find sshd there. The right side then shows Classes, Sources and JavaDocs. The JavaDocs part in my case had a path linked in that pointed to my local m2 directory. However the directory did not contain the javadoc jar file. So I thought how do I get it:
mvn dependency:resolve -Dclassifier=javadoc
Taken from here
However this failed for because we do not have some javadocs in our nexus (I guess, not sure).
So I ended up linking the file that I downloaded manually in as a javadoc link and this then allown me to use Shift+F1 for the javadoc to open in my standard browser.
Maybe others can elaborate on how to get this done with mvn. I did not have the time to further investigate.
Posting this here in case you're like me and don't necessarily want javadocs, but rather the documentation inside your IDE.
In my situation, I had downloaded OpenJDK 11 and wasn't able to get documentation inside IntelliJ. Instead I was getting decompiled code.
What helped me was the answer at https://stackoverflow.com/a/38413439
i.e.
Go to File > Project Structure > SDKs > Sourcepath > '+' on the right side.
Navigate to your JDK (I'm on Ubuntu so it was located under /usr/lib/jvm/openjdk-11/).
Select the src.zip (for me, /usr/lib/jvm/openjdk-11/lib/src.zip).
Click OK > OK (to "Choose Roots" pop-up) > OK (to Project Structure)
Let Intellij index and it should be available in your IDE.
Java 10 Documentation path
Got to File -> Project Structure Choose External URL
Below Link works Fine... THe default one does'nt work
https://docs.oracle.com/javase/10/docs/api/
Other answers are satisfying but in case you still can't see the documentation, make sure that your java file is located under the src path.

Why is the "Source Code Locations" page missing on eclipse 3.6 (Helios)

I'm trying to add JFace source code on my Target Platform in Eclipse 3.6.
Many help page on the internet refers to a "Source Code Locations" tab from the Target Platform preferences page.
I do not have that tab on a fresh Eclipse 3.6 including RCP development (eclipse-rcp-helios-SR1-RC4-win32.zip). Here's a screenshot of my Target Platform preferences page :
Any idea how add source code to my target platform ?
Many help page might refer to that tab, but the Eclipse Helios page doesn't.
As far as I can see, this is no longer available with Eclipse 3.6.
You can add your source when exporting your plugin, but that is not exactly the same.
The "Generating Source Features and Plug-ins" is still there though.
It was the alternative mentioned by the old Ganymede Help page
Declared Source Locations
An alternative way to ship source code locations is to use declared (pre-defined) source locations.
This is done by using the org.eclipse.pde.core.source extension.
A plug-in defining this extension will be treated as a source location.
The extension point schemas and source archive(s) for a plug-in are located in a unique subdirectory under one of these source code locations.
The name and structure of the subdirectories must follow a specific convention.