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)
*/
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...
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...
>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