I am building an app which connect to MySQL database using intelij idea. I have imported jdbc driver through modules > dependencies and it works great when I run the app through IDE. But when I build an artifact using build > build artifacts > rebuild (tried clean and build also) and I ran it using cmd I get the following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I have also tried cleaning and rebuilding project but it didnt help.
Any ideas what am I doing wrong?
The JDBC driver JAR file needs to be on the classpath when you run the code. For example, if you are running your application like:
java -jar Application.jar
You should use:
java -classpath /path/to/Driver.jar -jar Application.jar
Found a solution myself. Intelij idea was not adding new library dependency to artifact build path. So the solution is to recreate artifact and then module dependency is added. Or just add it manualy to artifact settings
Try to use maven, it resolve all dependencies for you.
In IDEA you can start maven project:
File->New->Project: chose Maven
You don't need to search & place your dependency jars in classpath manually, just add another one dependency in pom.xml and maven download it for you.
To know which dependency snippet you need you - just search it here
Related
I'm getting an error in eclipse "configure build path" for maven libraries which I have imported from maven.
And after cleaning the .M2 repositories of all libraries, updating the project, mvn installing and any thing else I could think of I still get these errors:
1 - Configure build path
2 - No class exist eclipse keeps sugesting that I use another annotation for EnableWebSecurity even tough its in the the build path...
Please help
There where two issues
1 - As stated by #howlger I needed into insert maven compiler for version 11 of java...
<properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target></properties>
2- Wrong dependency, I was using a diferent version for dependency. I used spring-core-security and needed to use spring-security-web-core
Thank you #howlger
I am trying to connect to Tigergraph DB from Spark using IntelliJ IDE. Can anyone help with the jdbc driver (.jar) file? I am looking for "com.tigergraph.jdbc.Driver".
I did find below gitHub repository with all the required .java file. But, I am not sure how to use it inside my spark project. https://github.com/tigergraph/ecosys/tree/master/tools/etl/tg-jdbc-driver
Can anyone help me on this?
It can be done quickly. I hope you are familiar with maven and git.
[[Command prompt]] git clone https://github.com/tigergraph/ecosys.git
Navigate to [[project checkout path]]\ecosys\tools\etl\tg-jdbc-driver
execute mvn clean compile install -Dmaven.test.skip=true
and then, once build is okay you will get the JAR in the folder
You can use this JAR afterwards in your project.
according to the GitHub documentation of tg-jdbc-driver repository, you need to build the JAR and then you can include this dependency in your pom.xml and start using it's API.
Some helpful resources:
https://medium.com/tigergraph/data-lakes-will-yield-more-business-value-when-combined-with-graph-databases-928181dffe24
https://www.programmersought.com/article/68114478380/
I am using the maven embedded eclipse.
Tried :
Deleting the whole m2 repository.
Maven->Update Project.
Run as -> Maven Build
User settings file does not exist(Please don't tell me it has to something with this file)
settings.Xml file
This file is only required if you are using a proxy and i am not
I have every dependency present in pom.xml file of my project but still eclipse is not able to import all these dependencies in the project
I have attached the photo below. Please help me to resolve my issue
mvn dependency:tree
Maven Dependencies
POM.xml file
List of dependency present in pom file of my project
None of the methods mentioned above worked so please help me to solve this issue.
Is there anything related to maven or eclipse version ?
When you execute mvn dependency:tree result shows an error related to "i cannot obtain some jar", it may be due to private reporitory.
If you are working with private repository, make sure you configure access in $HOME/.m2/settings.xml
On another hand I see you are working with snapshots. If you are trying to bind projects you have in your local host machine, ensure you are executing mvn install (or better mvn source:jar install) sucessfully and your system's maven is pointing the same .m2 path that refers Eclipse maven plugin
It seems using the Spring framework Maven repository via HTTP instead of HTTPS causing this issue.
In your pom.xml file replace http://maven.springframework.org with https://maven.springframework.org.
I have a maven project in Eclipse and I added some local jar files to the buildpath. If I do not add any dependency to the pom.xml file I am able to execute maven install. Then, if I add those dependencies to the pom the command maven install continues working as well. Now in this situation if I run maven clean then maven install fails. Why?
I also tried to run Maven -> Update Project but the result is the same. What is the problem?
If you are using non maven dependencies then it will fail to build eg from CLI and in your case in Elipse after cleaning the project as well. In order to make it work you have to installl tha JAR you are using as Maven artifact and the ninclude it in POM dependencies like every other library.
Here you have info on how to install 3rd party JARs to local repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I got the same problem and resolved by adding the 3rd party in the pom.xml manually
I'm trying to use MaxMind's GeoIP2 database, I've added the jar to my Java build path and configured it with Javadoc and source but when I run the program I get a NoClassDefFound error, which according to this stack overflow answer is because I need to add the dependencies, but I have no clue how to add them in eclipse, I tried extracting the jar files and adding them to the build path but that didn't work, how do I do this in eclipse?
Thanks for any help.
In eclipse you have to create a new maven java project. If you dont know maven you can get informations here:
apache maven startsite
how to install maven
Afer that you are able to configure your dependencies in your pom.xml file. Which is the configuration file for maven.
You can find some dependencies for your usage here:
maxmind documentation
The include of the dependency would look like this:
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>v2.3.0</version>
</dependency>
But first, you should look at maven installation and using. It will make your life easier by handling all the necessary dependencies you will need in this project and in all of your other projects in future.
You don't need to use Maven
For Eclipse, you may use Rightclick on Project > Properties > Java Build Path > Add External JARs. Select the JAR file you downloaded.