0

In my project, I have created a custom JDBC driver and I want to put it in a jar file. I also know that JDBC driver registration via DriverManager can be automated if I put the appropriate file in the services folder of the META-INF directory inside the jar file. But I can't find a way to put a folder named "services" in the META-INF directory of the jar file, and also put the appropriate file in the services directory, which will make the registration of the JDBC driver automatic. please tell me how to do it.

EDIT: I want to put the "services" folder in the jar file during jar file creation, not after jar file creation.

Vahag Chakhoyan
  • 873
  • 1
  • 10
  • 21
  • 2
    How are you trying to do this? As a part of the build? After the jar is already built? – Paul Samsotha Mar 21 '22 at 16:09
  • @PaulSamsotha As part of the build, not after the jar is already built. – Vahag Chakhoyan Mar 21 '22 at 16:34
  • How are you building this? Are you using Maven or Gradle, then put it in `src/main/resources/META-INF/services/java.sql.Driver`. If you're manually building a JAR, then you just need to make sure a `META-INF/services/java.sql.Driver` is added to the jar. – Mark Rotteveel Mar 21 '22 at 16:40
  • @MarkRotteveel here is the command line command, that I am using to create jar "jar cmf java_api_version.mf myJDBC.jar -C d:/dev com" – Vahag Chakhoyan Mar 21 '22 at 16:48
  • @MarkRotteveel but jar command creates META-INF directory automatically, how can I make sure that META-INF/services/java.sql.Driver is added to the jar? – Vahag Chakhoyan Mar 21 '22 at 17:01
  • 1
    You just need to have the directory `META-INF/services` with the file `java.sql.Driver` in the same location as your classes. If you do `jar -cvf your.jar *` it will include that file. The only reason jar creates `META-INF` automatically is because it generates `META-INF/MANIFEST.MF`, that doesn't mean you cannot add other files to META-INF. – Mark Rotteveel Mar 21 '22 at 19:17

0 Answers0