0

I'm trying to use a java lib to connect to a database, im doing the tutorial outlined here, http://www.homeandlearn.co.uk/java/connect_to_a_database_using_java_code.html

and I can get it to work in netbeans by putting the .jar into the library file in my project file but I don't have a clue how to get it to work hen using an ide such as vim. can someone help?

Kieran Lavelle
  • 446
  • 1
  • 6
  • 22
  • Why do you need to use an "IDE such as vim"? You'd need to manually set up your CLASSPATH. – Thilo Dec 08 '14 at 10:46
  • 3
    Vim isn't an IDE; use it just for editing text (and Java source code), and leave compilation and execution to other tools (such as Ant, Maven, make). You're likely confusing many things as a beginner. Go slow, maybe stick to Netbeans so far if you're feeling comfortable with it. – Ingo Karkat Dec 08 '14 at 10:49
  • Because I think something like vim is far more better for the type of work I do and don't want to be using net beans every time I use a librabry. I tried doing, javac -classpath derbyclient.jar database.java, and then running it using java -classpath derbyclient.jar database ,, the derby client was in the same file as the jar – Kieran Lavelle Dec 08 '14 at 10:49

4 Answers4

1

If I got your question right, you can find the right answer on this other StackOverflow post:
how to include libraries in java without using an IDE
You need to build both files into a JAR file, then you can run it.
I hope this helps.

Community
  • 1
  • 1
andlon10
  • 55
  • 5
1

A build tool which features dependency management such as Maven will help solve this problem. To use Maven you will add the location of libraries you require to an XML file (pom.xml) and Maven will download them for you and incorporate them in your target application archive (e.g. a war file).

Maven central provides a means to search for dependencies. In your case you can find the Derby client jar here. Click on the version of the library you would like to use and you'll see the sections of build descriptor code you needs to copy and paste in for: Maven, Ivy, and a few other popular build/dependency management tools.

Once you are comfortable with Maven, you could look up the Maven "Shade" plugin which will help you create a single jar file containing the necessary dependencies to run your application.

antonycc
  • 76
  • 1
  • 4
0

Vim, is more of an editor than an IDE, so you will need to specify the library .jar files manually on your class path when running your application.

You can do this by specifying the -cp parameter to the Java executable. e.g.

java -cp driver.jar MyMainClass
Dave
  • 1,303
  • 7
  • 19
0

The way you are trying to use the library you desired requires manually adjusting your CLASSPATH. Oracle has some detailed instructions on that: PATH and CLASSPATH.

Though, I would suggest to use some kind of build tool which makes it easier to handle your applications dependencies.

In the Java world, the most convenient tools are Ant, Maven and Gradle.

I feel you have just started Java development, so I would prefer Gradle in your case, although Maven is still pretty widely used in projects.

With these build tools handling dependencies will not be -lets say- wired in the IDE and you can easily build your application in any environment.

Community
  • 1
  • 1
ragklaat
  • 926
  • 5
  • 12