0

I am using IntelliJ IDEA to develop a Java project. To include the mysql-connector-java library I use, I created a folder named lib in the root of the project and added the JAR to it. After that I added it as a global library using the context menu. When debugging it, everything is working fine. But when I navigate to the production directory and try to run it from the command line it cannot find the library. How can I include it in the production directory to allow accessing it when running my main class? Or is there another way to get this done? I just want to make sure, that all external libraries my project is depending on are properly included.

urbaindepuce
  • 503
  • 1
  • 5
  • 17

2 Answers2

2

in the command line you should use -cp to add jars or directories to classpath (as explaind here ). if you want to run with intellij Idea then you create a run configuration (which I thing you've already done) and then in the configuration select you module in option use class path of module part of the configuration.

hasan
  • 966
  • 2
  • 13
  • 40
  • What I wanted to do is to automatically include all the JAR files in the build directory. I thought that way I don't have to fiddle around with classpath and have one single directory to give to classmates. But it seems that this is not how it is done. – urbaindepuce Jan 01 '15 at 15:17
  • generally you should use build tools for this purpose. [ant](http://ant.apache.org/manual/using.html) is a good starting point. – hasan Jan 01 '15 at 19:37
0

You have to add the library/jar to your BuildPath.

Just take a look at the "Correct way to add a library to an IntelliJ project"

Community
  • 1
  • 1
EssenceBlue
  • 403
  • 5
  • 13