We help IT Professionals succeed at work.

Problem running *.jar file java.lang.NoClassDefFoundError

mruff asked
when I try to run my pgm with: D:\Data\mruff\spectroCVS\Projects\B2BServer>D:\Applications\Programming\Java\jdk
1.3\bin\java.exe -jar B2BServer.jar
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: com/wbk/B2BServerAppl
I have the following manifest file:
Manifest-Version: 1.0
Created-By: 1.3.0 (Sun Microsystems Inc.)
Main-Class: com.wbk.B2BServerApplication
Class-Path: . D:\Applications\Programming\Java\jdk1.3\jre\lib\rt.jar D:\Data\mruff\spectroCVS\Projects\B2BServer\lib D:\Data\mruff\spectroCVS\Projects\B2BServer\lib\jdom.jar D:\Data\mruff\spectroCVS\Projects\B2BServer\lib\xerces.jar D:\Data\mruff\spectroCVS\Projects\B2BServer\lib\mysql.jar D:\Data\mruff\spectroCVS\Projects\B2BServer\lib\FTPProtocol.jar D:\Data\mruff\spectroCVS\Projects\B2BServer\lib\OROMatcher.jar D:\Data\mruff\spectroCVS\Projects\B2BServer

I put the files in the following directory structure:
then I jar all. I can see the Manifest.mf file is in the jar file at the correct loacation.
I have no idea what is wrong here
P.S. in the manifest file I also tried with slahes as delimiters (Main-Class: com/wbk/B2BServerApplication) did not work either
Watch Question


What is the output of jar -tf B2BServer.jar?

do you have the declaration:
package com.wbk;
at the top of your B2BServerApplication.java file?

if you have jar your classes correctly, then i can say that it is the class path for that jar is not setted correctly.

For example, B2BServer.jar resides in D:\jar
then you need to set your D:\jar in the classpath. Otherwise it cannot find the class and will give you NoClassDefFoundError
Mick BarryJava Developer
Top Expert 2010

> For example, B2BServer.jar resides in D:\jar
> then you need to set your D:\jar in the classpath.

That will NOT pick up B2BServer.jar.
jar's must be explicitly included in your classpath, or simply placed in your ext directory where they will get automatically included.

Sounds like you haven't included your files in your jar correctly.

To Objects:

i supposed you are referring to weblogic server when you mention "ext directory".

It seems to be a bug, whereby it doesn't automatically include the jars.
Mick BarryJava Developer
Top Expert 2010

What's weblogic got 2 do with it??

(Since 1.2) Any jar file placed into the ext folder located inside your jre installation will be included in your classpath.

But I don't think the problem is with the command line, or classpath. The problem appears to be with the construction of the jar file.


to stimpyjcat :
I build the the jar file with the following ant-script
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="dist" name="B2BServer">

  <!-- set global properties for this build -->
  <property name="src" value="src"/>
  <property name="build" value="build"/>
  <property name="dist" value="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>

  <target depends="init" name="compile">
    <!-- Compile the java code from ${src} into ${build} -->
     <javac destdir="${build}" srcdir="${src}">
          <pathelement path="${classpath}"/>
          <fileset dir="./lib">
            <include name="**/*.jar"/>
            <include name="**/*.class"/>
          <pathelement location="./build"/>

  <target depends="compile" name="dist">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>
    <mkdir dir="${build}/META-INF"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar basedir="${build}" jarfile="${dist}/lib/B2BServer-${DSTAMP}.jar" manifest="./manifest/MANIFEST.MF"/>
    <copy file="${dist}/lib/B2BServer-${DSTAMP}.jar" tofile="./B2BServer.jar"/>
    <!-- Delete the ${build} and ${dist} directory trees -->
  <target depends="dist" name="clean">
    <delete dir="${build}"/>
    <delete dir="${dist}"/>


to black: yes, I can run the application without any problem, if the *.class files are not packed in a *.jar file
there is an error in your manifest file:
Class-Path: The URLs in the Class-Path header are given relative to the URL of the JAR file
if you have for example a lib folder in the folder where your B2BServer.jar resides, then the class-path should look like:

Class-Path: . lib/rt.jar lib lib/jdom.jar lib/xerces.jar lib/mysql.jar lib/FTPProtocol.jar lib/OROMatcher.jar B2BServer.jar


that was the answer, now it works
a tool named JavaJar
can compress and decompress war, ear and jar....

may download from http://www.qwerks.com/download/4114/JavaJar.zip

the tool is very good tool.
but the homepage(www.pivotonic.com) of JavaJar cannot be  accessed.

it is funny.