Jump to content

Recommended Posts

Posted (edited)

Hello,

i'm currently working on a mysql database which im trying implement in with my minecraft project.

My problem is, that if i export my project (with the minecraft classes of course) it throws an ClassNotFoundException for "com.mysql.cj.jdbc.Driver"

Strangely, its working in debug mode but not when i export it.

I have also already added the correct mysql-connector.jar to the libraries, as well as searching for reasons online..

I hope that someone will the cause for this and help me out with it.

 

Console output: 

01:47:16	game		info	java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
01:47:16	game		info	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
01:47:16	game		info	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
01:47:16	game		info	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
01:47:16	game		info	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
01:47:16	game		info	at java.lang.Class.forName0(Native Method)
01:47:16	game		info	at java.lang.Class.forName(Class.java:264)
01:47:16	game		info	at me.freakzboy.testclient.TestClient.startClient(CountDown.java:41)
01:47:16	game		info	at net.minecraft.client.Minecraft.startGame(Minecraft.java:575)
01:47:16	game		info	at net.minecraft.client.Minecraft.run(Minecraft.java:410)
01:47:16	game		info	at net.minecraft.client.main.Main.main(Main.java:114)
01:47:16	game		info	jdbc driver unavailable!

 

	public void startClient() {
		
		instance = this;
		
		try {
			
		    Class.forName("com.mysql.cj.jdbc.Driver");
		    
		    //this accesses Driver in jdbc.
		} catch (ClassNotFoundException e) {
		    e.printStackTrace();
		    System.err.println("jdbc driver unavailable!");
		    return;
		}
		MySQL.connect(); 
    	}

 

	public static void connect() {
		
		if(isConnected() == false) {
			try {
				
				con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
				
				System.out.println("[MySQL] Successfully connected!");
				
			} catch (SQLException e) {
				
				System.out.println("[MySQL] Error.");
				
				e.printStackTrace();
			}
		}
		
	}

 

Thanks,

Freakz

Edited by FreakzBoy
Posted

Minecraft does not ship with this package, you have to shade it into your compiled jar.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 8/25/2018 at 1:01 PM, diesieben07 said:

Shading is inferior to the jar-in-jar mechanism in Forge.

Expand  

Good to know. Hadn't heard about this, or if I did, I didn't know it was different.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Hey, thanks for you responses. Wouldn't packaging the mysql-connector-java.jar file also be a solution to this?

Edited by FreakzBoy
Posted (edited)

Ok, i tried packaging the mysql-connector-java.jar after i exported my minecraft project and (put the com folder as well as the META-INF folder into my minecraft jar). Unfortunately, its still throwing the ClassNotFoundException: com.mysql.cj.jdbc.Driver and doesnt connect to my mysql database. I did some research on the internet too, and people were talking about dependencies in the META-INF folder and pom.xml which I'm not familiar. Any ideas?

Edited by FreakzBoy
Posted

Yes i did, I've also tried putting the jar into my minecraft jar, which forge is supposed to extract into the mod repository and load them. For me this is not the case tho. That's why i've also tried the method written above

Posted (edited)

I forgot to mention that i'm not working on a mod thats going to be added, but on a whole minecraft client that should connect to the database. I basically export my client jar and place the things that are inside it into a normal minecraft jar, thats how i can basically start my client in the launcher. I dont know if you had experience with clients in general yet or only with mods, but it should be close to the same. By the way the link you have posted above, tells me, that i have to put dependency jars into my jar, which i can only get by converting my project into Maven. Is that correct?

Edited by FreakzBoy
Posted

Do not create clients.

This is not negotiable or debatable, thread locked.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.