again me.
I dont know what the hell isnt working right, but everytime im exporting my Teamspeak Bot wrote in Java, it seems like he dont export the mysql-connector.jar.
Everytime im trying to start my jar, he always tells me that he cant find the MySQL-Driver.
Heres my Code:
As you can see, the jar file is in the buildpath. When i try running it through Eclipse, everything works fine. Only when im exporting he throws me the Exception.
Hope someone of you can help me.
ndslr
The way you're exporting your jar, your library jar isn't automatically added to the output jar. You would have to specify the classpath when you run it:
java -cp "C:\Users\Andy\Desktop\mysql-connector.jar;YourOutputJar.jar" TS3BotMySQL
Instead, you have to add the mysql-connector.jar to your output jar. To do this, instead of going to export > jar, go to export > runnable jar, and then select "Extract required libraries into generated JAR" or "Package required libraries into generated JAR" at the prompt.
See these related questions for more information:
How to create a jar with external libraries included in Eclipse?
Eclipse Java; export jar, include referenced libraries, without fatjar
Generating a Jar in Eclipse including external library
How export Java jar from Eclipse with dependencies on other jars?
Related
I have included libraries using File->Project Structure->Libraries:
In Artifacts, I made sure to include the library in the output JAR file:
When I run the program inside IntelliJ, it works fine. However, when I try to run the JAR file it generates, it displays a NoClassDefFoundError:
So the libraries aren't working. How can I get libraries to work in IntelliJ?
(I have never run into the problem before...)
I have generated an executable jar in IntelliJ IDE. But when I try executing the jar file from windows folder it does not work. When I try running the .jar file from within the IDE in debug mode it gives the below error:
no main manifest attribute, in D:\... the file path
To generate the executable jar I referred to Link
I referred to Link for the no main manifest attribute issue but dint help as in my case its a Gradle build
(Note: If I execute the program(.java file) from within the IDE it works fine, so I believe the issue is not with the program)
Hope the issue I face is clear, await guidance
Adopted Gradle build tool to generate Jar.
I'm learning Hadoop under VMware now.(win7, 64) Due to some reason, I can't convert a .java file to .jar file under virtual machine, so I tried to create .jar file under Eclipse.
I'm currently using Eclipse MARS(4.5.1). I need to download something about fat jar, but I can't find it online.
My colleague copied his Eclipse software to me. It is already installed, so I copied the whole package. It is Eclipse Kepler. So I am running two Eclipse software on my computer now. will this cause some problem? (I saved projects seperately)
I can do the convert .jar file thing correctly on Eclipse Kepler now. But I still want to use MARS and delete the extra Eclipse.
thank you !
What you're looking for is the "Fat JAR" eclipse plugin.
Fat jar is a jar which contains all the classes used by the project including their referenced dependencies.
The plugin can enable the creation of such a jar.
In your case, however, Eclipse "Mars" & Eclipse "Kepler" include this functionality. The trick is to get to it...
Here's what you do in order to export a Fat JAR:
Right-click on the required Project and select "Export..." --> "Runnable JAR file".
Select the option which extracts libraries and specify the destination JAR file.
Launch configuration is used to execute this JAR with a predefined "Main" class (this is the "Runnable" part...) using "java -jar file.jar".
If you don't plan to - it won't matter.
(Optional) You can also "Save as ANT script" which, well..., generates XML ant script as well.
select project
select Export
Expand the Java node and select JAR file. Click Next
In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field
.
Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source
or go to http://www.codejava.net/ides/eclipse/how-to-create-jar-file-in-eclipse
I want to create an Android project that contains some code, and then export that code as a .jar file to use it on another Android project.
I've already tried to create an Android project and set it as a library in the properties, and then export the project as a jar file. Aparently everything works fine, when I use my .jar file as a user library in another Android project my code inside the .jar is visible and everything compiles fine. But when I run my application it closes and say that it could not find the classes inside the .jar file.Any sugestions will be very appreciated!Thanks in advance.
Look at Project->Properties->Java Build Path->Order and Export. Make sure your jars are exported as well as imported.
Make sure your JAR is in the libs/ directory of the project using the JAR, and that it is in your build path in Eclipse.
I have developed an application using Eclipse IDE. After creating the application I exported the project in jar format. When I am trying to run this jar file, I get the error: Unable to load main class. Please Help.
When you are exporting your project as a jar (see this SO question), you must specify your main class in the export Jar wizard.
This should work always:
java -cp MyJar.jar pkg.name.MyClass
I'd prefer this anyway because it causes less classpath trouble compared to the java -jar way of starting a java application.
You need to create a runnable jar file. From Eclipse 3.4 you can do that by choosing Export, Java, Runnable Jar File. If you also want to include dependencies have a look at the Fat Jar plug-in.