Board index » jbuilder » NoClassDefFoundError ... wrong name

NoClassDefFoundError ... wrong name


2004-04-06 03:48:55 AM
jbuilder24
I am having a problem trying to use a third-party Java class library.
Although it works from within a Java application, I am getting this error
message when I try to use it from within Cold Fusion (Oh how I wish Borland
had bought Allaire! May not be too late.).
I am trying to instantiate the object with this line:
<cfset mp3x = createObject("java", "de.vdheide.mp3.MP3File").init()>
And I get this error message:
java.lang.NoClassDefFoundError: de/vdheide/mp3/MP3File (wrong name:
mp3/de/vdheide/mp3/MP3File)
I want to point out there is a difference in the two references here. The
first says "de/vdheide" and the second says "mp3/de/vdheide". I have no idea
where that initial mp3 reference is coming from in the "wrong name" clause.
I've thought of these problems:
* Mistake in my CF code? But the same syntax works on other classes (see
below).
* Mistake in the MP3File library? But it works in regular Java apps.
* Mistake in the JVM's classpath? So I wrote the ClassPathManager class at
the bottom of this and it confirms that the file is in the classpath (and
that the CF syntax works).
* A mistake in the MP3File import or package reference? I included it
below.
Does anyone know what might cause this or how to resolve it? I'm especially
confused by the fact that "wrong name" reference is different from the
other.
Thanks
Scott
/ **********************************************************************
* Here is the heading for the MP3File definition.
* The class works when I use it within a regular Java application. It is
downloaded from
* www.vdheide.de/projects.html.
*
* I am putting this file here:
* C:\Program Files\Java\_jvm\lib\de\vdheide\mp3\MP3File.class
*
* Note that de.vdheide.mp3 appears in both.
* My classpath is set to include c:\program files\java\_jvm\lib
* The Java class I've included below does list th MP3File in that directory
as available within
* the JVM context for my app server.
********************************************************************** /
package de.vdheide.mp3;
import java.io.File;
import java.io.IOException;
public class MP3File extends java.io.File
{
/* stuff goes here */
}
/ **********************************************************************
* Here is the ClassPathManager source code, which I compiled and put in the
classpath for CF.
* Calling this class from within Cold Fusion, shows that the MP3File.class
file is available in
* the JVM's classpath. Here is how to call it from within CF:
* <cfset cpm = createObject("java", "ClassPathManager").init()>
* <cfset classes = cpm.getClasses()>
* <cfdump var="#classes#">
*
* Feel free to use this wherever you need to double check class
availability.
* It returns a string array to make it as easy as possible to use in
different environments.
********************************************************************** /
import java.io.*;
import java.util.*;
public class ClassPathManager {
private StringTokenizer classpath;
private TreeSet fileHashSet;
public ClassPathManager () {
super();
classpath = new StringTokenizer(System.getProperty("java.class.path"),
";" );
fileHashSet = new TreeSet();
}
public String[] getClasses() {
while (classpath.hasMoreTokens()){
listDirectory(new File(classpath.nextToken()));
}
String[] arrayOfFiles = new String[0];
arrayOfFiles = (String[]) fileHashSet.toArray(arrayOfFiles);
return arrayOfFiles;
}
public void listClasses(){
String[] fileNameArray = getClasses();
for (int x=0; x<fileNameArray.length; x++){
System.out.println(fileNameArray[x]);
}
}
public void listDirectory(File entry){
try {
if (!entry.exists()){
return;
}
if (entry.isFile()){
fileHashSet.add((String) entry.getCanonicalPath());
}else if (entry.isDirectory()){
String [] fileName = entry.list();
if (fileName == null) return;
for (int i = 0; ifileName.length; i++){
File item = new File(entry.getPath(), fileName[i]);
listDirectory(item);
}
}
} catch (IOException e) {
System.err.println ("Error: " + e.getMessage() + " on " +
entry.getName());
}
}
}
 
 

Re:NoClassDefFoundError ... wrong name

Recompiling all of the .java files seems to have fixed it.
Thank god for the GUI tool's ability to compile everything in a project --
compiling one by one from the command line wasn't working.
"Scott" < XXXX@XXXXX.COM >wrote in message
Quote
I am having a problem trying to use a third-party Java class library.

Although it works from within a Java application, I am getting this error
message when I try to use it from within Cold Fusion (Oh how I wish
Borland
had bought Allaire! May not be too late.).

I am trying to instantiate the object with this line:
<cfset mp3x = createObject("java", "de.vdheide.mp3.MP3File").init()>

And I get this error message:
java.lang.NoClassDefFoundError: de/vdheide/mp3/MP3File (wrong name:
mp3/de/vdheide/mp3/MP3File)

I want to point out there is a difference in the two references here. The
first says "de/vdheide" and the second says "mp3/de/vdheide". I have no
idea
where that initial mp3 reference is coming from in the "wrong name"
clause.

I've thought of these problems:
* Mistake in my CF code? But the same syntax works on other classes (see
below).
* Mistake in the MP3File library? But it works in regular Java apps.
* Mistake in the JVM's classpath? So I wrote the ClassPathManager class
at
the bottom of this and it confirms that the file is in the classpath (and
that the CF syntax works).
* A mistake in the MP3File import or package reference? I included it
below.

Does anyone know what might cause this or how to resolve it? I'm
especially
confused by the fact that "wrong name" reference is different from the
other.

Thanks
Scott

/ **********************************************************************
* Here is the heading for the MP3File definition.
* The class works when I use it within a regular Java application. It is
downloaded from
* www.vdheide.de/projects.html.
*
* I am putting this file here:
* C:\Program Files\Java\_jvm\lib\de\vdheide\mp3\MP3File.class
*
* Note that de.vdheide.mp3 appears in both.
* My classpath is set to include c:\program files\java\_jvm\lib
* The Java class I've included below does list th MP3File in that
directory
as available within
* the JVM context for my app server.
********************************************************************** /
package de.vdheide.mp3;

import java.io.File;
import java.io.IOException;

public class MP3File extends java.io.File
{
/* stuff goes here */
}




/ **********************************************************************
* Here is the ClassPathManager source code, which I compiled and put in
the
classpath for CF.
* Calling this class from within Cold Fusion, shows that the MP3File.class
file is available in
* the JVM's classpath. Here is how to call it from within CF:
* <cfset cpm = createObject("java", "ClassPathManager").init()>
* <cfset classes = cpm.getClasses()>
* <cfdump var="#classes#">
*
* Feel free to use this wherever you need to double check class
availability.
* It returns a string array to make it as easy as possible to use in
different environments.
********************************************************************** /
import java.io.*;
import java.util.*;
public class ClassPathManager {
private StringTokenizer classpath;
private TreeSet fileHashSet;


public ClassPathManager () {
super();
classpath = new StringTokenizer(System.getProperty("java.class.path"),
";" );
fileHashSet = new TreeSet();
}

public String[] getClasses() {
while (classpath.hasMoreTokens()){
listDirectory(new File(classpath.nextToken()));
}

String[] arrayOfFiles = new String[0];
arrayOfFiles = (String[]) fileHashSet.toArray(arrayOfFiles);
return arrayOfFiles;
}

public void listClasses(){
String[] fileNameArray = getClasses();

for (int x=0; x<fileNameArray.length; x++){
System.out.println(fileNameArray[x]);
}
}



public void listDirectory(File entry){
try {
if (!entry.exists()){
return;
}

if (entry.isFile()){
fileHashSet.add((String) entry.getCanonicalPath());
}else if (entry.isDirectory()){
String [] fileName = entry.list();
if (fileName == null) return;
for (int i = 0; ifileName.length; i++){
File item = new File(entry.getPath(), fileName[i]);
listDirectory(item);
}
}
} catch (IOException e) {
System.err.println ("Error: " + e.getMessage() + " on " +
entry.getName());
}
}
}