Cannot reference jdbc.SQLServerDriver in Eclipse (ClassNotFoundException) - sql

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

Related

JavaFX can't build artifact - fx:deploy is not available in this JDK

I have a JavaFX project that I would like to build as a Jar-file. However, when I attempt to do so, I get an error.
Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK
I found a similar problem on here from last year, but it seemed like they concluded nothing.
This happens because either you have many JDKs installed and compiling by another and running by another or you are using the Javafx Application jar feature when creating artifacts in Intellij which is unfortunately broken. Before proceeding with the below steps make sure that you are compiling with and running with the same JDK version.
Here is you fix it:
1 - Create a Launcher class:
The Launcher class is going to call the main JavaFx class from which your appliaction runs. Choosing to make the Jar directly through the Main class is going to error out giving the following error:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
Your Launcher class should look something like this:
public class Launcher {
public static void main(String[] args) {
MainGUI.main(args);
}
}
2 - On to building the Jar
You probably still have a META-INF folder from the previous build so delete it.
Build the project as a JAR:
File->Project Structure -> Artifacts -> "+" -> JAR-> from modules with dependancies..
Choose the Launcher class for you main and check "copy to the output directory and link via Manifest" and Press Ok
Press Apply then OK.
go to Build -> Build artifacts-> Rebuild
In the JetBrains website I found a good article about, Package JavaFX applications which was really helpful. In the #troubleshoot section it says that,
Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK
The fx:deploy task was a part of the Ant plugin that was formerly
distributed in ant-javafx.jar as a part of Java Packager. The Ant
plugin is not included in jpackage in the current JDK versions.
If you're using a JDK build of version 9 and later, use third-party
solutions for packaging. For example, refer to section Runtime images
in the JavaFX official documentation.

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.

Conversion of jar to dll using ikvm

I am trying to convert a jar into dll in dotnet using IKVM but am getting this error Exception in thread "main" java.lang.ClassNotFoundException: \Location of the jar\...
CAn anyone provide some guidance..
Thanks in advance
Prerequisites -
You must have the JDK installed on your system.
Set the environment variables for the JDK.
Steps:
Open the command prompt.
Go to the ikvmc folder (ikvmc.exe comes with the ikvm package).
Enter the command ikvmc -out:myapp.dll myapp.jar
First, create a new Bindings Library project. In Xamarin Studio or Visual Studio, create a new Solution and select the Android Bindings Library template.
The template includes a Jars folder where you add your .JAR(s) to the Bindings Library project. Right-click the Jars folder and select Add > Existing Item:
Navigate to the .jar file downloaded earlier, select it and click Add:
Verify that the .jar file was successfully added to the project:
right click your jar file=>properities =>choose embedded jar
Set the build action to EmbeddedJar:
EmbeddedJar – the .JAR will be embedded in the Bindings Library.
Set the target API level for your Bindings Library
Finally, build the Bindings Library. Although some warning messages may be displayed, the Bindings Library project should build successfully and produce an output .DLL at the following location:
Projectname/bin/Debug/JarBinding.dll
Reference
https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/
Is it possible that you forgot reference all needed IKVM .Net dlls?
IKVM.Runtime.dll
IKVM.Reflection.dll
IKVM.OpenJDK.*.dll
I've got something similar with SmsLib .Net version
The follow wiki pages should be helpful:
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=Ikvmc
http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=Ikvmc_messages

IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath

When I try to make a simple module in IntelliJ it responds with:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.
Goto:
File -> Project Structure -> Platform Settings -> SDKs
Re-apply the JSDK home path.
Doing this added about 15 jars to the classpath. Apparently these are important for compiling.
File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.
Works for me in IntelliJ 2017.3.
This error happend to me after i've updated my JDK version to jdk1.8.0_161 -
But the project's sdk was still pointing to the old jdk 1.8.0_131
(Seems that updgrading java causing the previous version to be wiped).
Do this:
In the IntelliJ IDE go to File > Project Structure, from there:
Within Platform Settings > SDKs:
Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161).
Within Project Settings > Modules:
Make sure that the Module SDK is set to the same entry you picked in the Platform Settings > SDKs
Save & Build again.
This worked for me:
In Preferences Build Tools > Maven > Runner > Environment Variables set JAVA_HOME to your JDK home path.
Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs under JDK home path.
e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
In Intellij Community 2019.1, this is what I did to solve the issue
Project Structure > Platform Settings > SDKs
Removed all existing SDKs listed ( I had multiple SDK listed there)
Add the required SDK only and Apply
File > Project Structure
JDK home path : PASTE_THE_JDK_LOCATION (Like here in the "Project Structure screen shot"
Build Again
Cheers :)
After following this answer,
I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml contained incorrect entries. Fixing the JDK table fixed the problem.