IntelliJ generated JAR, libraries don't work - java

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...)

Related

Or-tools java.lang.NoClassDefFoundError: com/sun/jna/Platform

Hi I'm trying to run this sample code on my eclipse ide and have manually adding the jars file without using the pom file provided but it's complaining with this error.
I managed to compile and run the sample code using 'make run' command.
Any idea is it possible to copy the library jar files and use it in my own project in eclipse?

Gradle JAR add to classpath

I am trying to use a number of external libraries in a Java project. The project runs fine from Intelij but I want to package it in a jar, (or something else) so I can distribute it to others. When I package it in a jar it works if I just do hello world, but as soon as I start using my libraries I get the error bellow. I have also tried packaging it as an application but when I run the batch file it just opens and then immediatly closes a command window. I read all the other posts and nothing is fixing my problem. Please help
My error
My build.gradle
The problem is most likely that your classpath does not point to the correct relative location of your 3rd party libraries. You can check the manifest file to verify if the paths are correct.
However, if it is a runnable jar file with a main method (which it looks like it is), you should use the Application plugin and package it with the Distribution plugin. Right now you are using the Java Library Distribution plugin, which is for libraries. If you do this, you can remove most of the stuff under your jar task.
When testing it locally, run gradle run and when ready, use gradle distZip to create a zip of it all. It will create a script used to start the application with the correct classpath.
Alternatively, you could also package it in a fat jar using the Shadow plugin or similar.

Java - IntelliJ generated executable jar not working

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.

Exception: com.mysql.jdbc.Driver | Eclipse isnt exporting jar

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?

Creating Android .jar files

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.

Categories