Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Probs with package names

0 views
Skip to first unread message

Albretch

unread,
Dec 12, 2000, 2:37:58 AM12/12/00
to
Hi,

I want to compile the following code in the package (directory)
com.my-name.

As far as I have understood the JLS the java compiler acts as sort of a
make utility saving the class files in the correct directory after
compilation.

I should be able to see both files there after I run the program right?

Well, I am getting a java.lang.NoClassDefFoundError error.

/* DEMO CODE */

package com.my\u00C4name;

import java.io.*;

c lass PXO{
int itI;
String azXML;
PXO(int itI, String azXML){ this.itI = itI; this.azXML = azXML; }
String getXML(){ return azXML; }
}

public c lass test00{
public static void main(String[] azArgs){
File Fl = new File("C:\\Java\\Dev\\com\\my-name\\");
if(!Fl.exists())Fl.mkdirs();
String[] azFls = Fl.list();
System.err.println( Fl.getPath() + ", azFls.length=" + azFls.length);
for(int itI=0; (itI < azFls.length);
+itI){ System.err.println(azFls[itI]); }
}
}

/*
Error I am getting

Exception in thread "main" java.lang.NoClassDefFoundError: test00 (wrong
name:
com/my-name/test00)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
*/


Jlowrie

unread,
Dec 13, 2000, 8:10:50 PM12/13/00
to
Let me try to straighten you out a bit....


0. change package declaration to:
package com.my.u00C4name
1. create a local directory structure that matches your package. In your
case let's call it c:\com\my\u00C4name
2. go to the root , in this case c:\
3. type javac .\com\my\u00C4name\PXO.java to compile
4. type java com.my.u00C4name.PXO to run
5. this will also work if you have a *jar* representing this directory
subtree in your classpath in lieu of the actual *.class files

"Albretch" <lbr...@hotmail.com> wrote in message
news:qBkZ5.5176$d62.3...@bgtnsc04-news.ops.worldnet.att.net...

Albretch

unread,
Dec 16, 2000, 3:09:02 AM12/16/00
to
but per the Java Language Specification

package com.my\u00C4name;

should actually produce the directory

com\my-name;

this is all I was trying to do. I wonder how did you do, what you claim.

Jlowrie <jflo...@home.com> wrote in message
news:u6VZ5.194757$td5.27...@news1.rdc2.pa.home.com...

Steve Atkinson

unread,
Dec 16, 2000, 4:04:33 PM12/16/00
to
On Sat, 16 Dec 2000 08:09:02 GMT, "Albretch" <lbr...@hotmail.com>
wrote:

>but per the Java Language Specification
>
> package com.my\u00C4name;
>
>should actually produce the directory
>
> com\my-name;
>
>this is all I was trying to do. I wonder how did you do, what you claim.

ok, lets assume you have a file "SomeClass.java" in package
"com.me.myclasses"

A straight javac SomeClass.java will produce the class file in the
current working directory, regardless of what package SomeClass is in.
a javac -dc:\MyClassesDir SomeClass.java will create the
SomeClass.class file in c:\MyClasses\com\me\myclasses directory (I'm
not sure if the directories have to exist first)

Check the javac documentation on sun's site http://www.java.sun.com

Hope this clarifies things a bit for you.

- Steve Atkinson

0 new messages