I am new to Java, and have run into an issue that has confounded me. I have an app, MyApp, that I wrote in IntelliJ. The app uses an external library, MyLib.jar that talks to a database, using sqljdbc42.jar from Microsoft. MyLib.jar and sqljdbc.jar are both set as External Libraries in IntelliJ.
The issue I have is that my app runs perfectly fine when I run it in the IDE, but when I use Generate Artifact to make a jar, the jar errors out when trying to connect to the database.
The error: class java.lang.ClassNotFoundException | com.microsoft.sqlserver.jdbc.SQLServerDriver
This is a class in sqljdbc42.jar. I am assuming this means that MyApp.jar can't see the classes in sqljdbc42.jar.
sqljdbc42.jar can't be included into MyApp.jar because of the way it is signed. Instead, I have the file in the same folder as MyApp.jar, and this is my MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: sqljdbc42.jar
Main-Class: com.mycompany.myapp.Main
And this is the file layout:
- MyApp_jar/
- sqljdbc42.jar
- MyApp.jar
I have another app set up the same way as far as I can tell, and that .jar works fine using the same class.
UPDATE - The .jar file I am attempting to include is a signed jar. Any other jar file I try to include works just fine. Here is a sample app to test:
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
public class Main
{
public static void main(String[] args)
{
try {
System.out.println(SQLServerDriver.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
And this is the jar I can't get to work: https://www.microsoft.com/en-us/download/details.aspx?id=11774 (4.2 version)