java - Getting ClassNotFound Exception when executing jar -


  • am using intellij 12.0.4 community edition.
  • i created java console app called db main class name of db.
  • i packaged executable jar file called db.jar.
  • in app connect oracle db using jdbc.
  • i packaged necessary jdbc jar files db.jar via intellij's project structure (modules, library)

  • when execute app within intellij runs successfully

  • if copy db.jar directory , execute via "java -jar db.jar" classnotfound exception on oracle.jdbc.driver.oracledriver
  • i looked in db.jar , jdbc jar files (ojdbc6.jar, ojdbc14.jar) in db.jar
  • any thoughts?

jars in executable jar not on classpath, typically.

you can put them in same folder db.jar , do:

java -cp db.jar;ojdbc6.jar;ojdbc14.jar <mainclass goes here> 

and should run it.

you put class-path entry in manifest.mf file inside jar reference other jars relative location of db.jar in computer's file system. reference 2 other jar files , can java -jar db.jar <mainclass goes here> (assuming 2 jars in right place.

there discussion here general frustration not being able want (and many others have wanted years).

classpath including jar within jar

explain main class

when run java application command line, there class execution starts. this:

package com.mycompany.app;  public class starthere {      public static void main(string[] args) {         // code goes here ...     } } 

if example class application starts use command line start it. assumes have starthere class in right package location in jar on classpath:

java -cp db.jar;ojdbc6.jar;ojdbc14.jar com.mycompany.app.starthere 

notice allows have multiple applications in same jar. make multiple classes main() method , run them different starting classes shown on command line.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -