| Author |
Package, ANT and Eclipse
|
|
| logiclips@yahoo.com 2005-10-28, 7:02 pm |
| Hi,
I have a small problem concerning ANT and Eclipse:
I have a project in Eclipse with one package and just one .java file
(e.g. HelloWorld.java) in it. The first line in this file is "package
test.mypackage;"
When I compile and execute it in Eclipse I have no problems but when I
do the same with ANT I get the following error:
java.lang.NoClassDefFoundError: HelloWorld (wrong name:
test/mypackage/HelloWorld)
A part of the build.xml file look like this:
<target name="compile">
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="run" depends="compile">
<java classname="TextEditor" classpath="${build}/test/mypackage/"
></java>
</target>
When I remove the first line ("package test.mypackage;") of my
java-file it works. But then all my class files are stored in one
directory without any package structure and I can not compile the code
in Eclipse any more.
Why is that? How can I overcome this?
Thanks in advance,
Peter Vermeer
| |
| Jan Peter Stotz 2005-10-28, 7:02 pm |
| logiclips@yahoo.com schrieb:
> I have a project in Eclipse with one package and just one .java file
> (e.g. HelloWorld.java) in it. The first line in this file is "package
> test.mypackage;"
> <target name="run" depends="compile">
> <java classname="TextEditor" classpath="${build}/test/mypackage/"/>
You classpath is wrong. If have to use classpath="${build}". The
subdirectory test/package will be converted to the package test.package by
the java runtime.
Jan
| |
| logiclips@yahoo.com 2005-10-28, 7:02 pm |
| I did that but then I get this error message:
"Could not find TextEditor. Make sure you have it in your classpath"
Isn't the classpath the path to the .class files?
P.S. "HelloWorld" = "TextEditor"
Peter
| |
| Oliver Wong 2005-10-28, 7:02 pm |
|
<logiclips@yahoo.com> wrote in message
news:1130517960.842270.289650@f14g2000cwb.googlegroups.com...
>I did that but then I get this error message:
> "Could not find TextEditor. Make sure you have it in your classpath"
>
> Isn't the classpath the path to the .class files?
No, it's actually the path to the directory that is the parent of the
root package where your class files are located (or sometimes it's a path to
a JAR file that contains the class files).
- Oliver
| |
| logiclips@yahoo.com 2005-10-28, 7:02 pm |
| Well, but then this should be right:
<target name="compile">
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="run" depends="compile">
<java classname="TextEditor" classpath="${build}" ></java>
</target>
when I just only have one package as discribed above.
What is wrong?
Thanks,
Peter
| |
| logiclips@yahoo.com 2005-10-28, 7:02 pm |
| OK, I've got it.
It has to be like this:
<target name="run" depends="compile">
<java classname="test.mypackage.TextEditor" classpath="${build}"
></java>
</target>
Peter
|
|
|
|