Results 1 to 5 of 5
  1. #1
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Include Jar Files for program.

    I created a small game, that uses a database (H2), and some other things to play with java. The program works fine when I compile it with Eclipse, but it will not compile/run when I try to do so in command line. The program will run, but gets an error when connecting to the database. My folders are set up like this

    BSGame/
    bsg/ - package
    bin/
    *.class
    lib/
    *.jar and *.save files
    src/
    *.java files

    Quest/ - package
    bin/
    *.class
    src/
    *.java

    And the line I use to run this:

    java -cp bin; bsg.bstart.class

    However, the database will not connect, even though the driver is in the lib folder, anyone know how to include the lib folder?


    Also, does anyone know how to compile? When I use:
    javac -d bin -s src src\to\path
    it doesn't work, but it isn't as much of a big deal...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Include Jar Files for program.

    What error do you get?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Re: Include Jar Files for program.

    Java Code:
    		try{
    			Class.forName("org.h2.Driver");
    			conn = DriverManager.getConnection("jdbc:h2:lib/bsg", "skania","---");
    			System.out.println(conn);
    		}
    		catch(ClassNotFoundException error){
    			System.out.println("Error: " + error.getMessage());
    		}
    Is the code I use to connect to the db, and here is what I get

    Java Code:
    Error: org.h2.Driver
    And this code works just fine when compiled and ran in Eclipse.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: Include Jar Files for program.

    Quote Originally Posted by skania View Post
    Java Code:
    		try{
    			Class.forName("org.h2.Driver");
    			conn = DriverManager.getConnection("jdbc:h2:lib/bsg", "skania","---");
    			System.out.println(conn);
    		}
    		catch(ClassNotFoundException error){
    			// System.out.println("Error: " + error.getMessage());
    			error.printStackTrace();
    		}
    Make the change in line 7 of your code and post the stack trace.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Re: Include Jar Files for program.

    Java Code:
    C:\Users\-----\Desktop\Projects\Learning Java\Exercise Files\BlackSmithGame>java -cp bin; bsg.BSGam
    e
    Crafted Spirit is loading...
    java.lang.ClassNotFoundException: org.h2.Driver
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at bsg.BSGame.main(BSGame.java:26)
    Finished!
    
    Would you like to load a previously saved game?

Similar Threads

  1. Runnable jar does not include my resource files
    By owboateng in forum Eclipse
    Replies: 2
    Last Post: 05-09-2011, 01:54 PM
  2. Replies: 0
    Last Post: 03-02-2010, 08:28 AM
  3. include-prelude/include-coda
    By devin in forum Java Servlet
    Replies: 0
    Last Post: 02-11-2009, 07:33 PM
  4. Replies: 5
    Last Post: 07-29-2008, 02:13 PM
  5. jsp:include and include file
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-14-2007, 04:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •