File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.ClassNotFoundException: when I put my code into a package

 
Guy Harel
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing java using DOS and a simple editor.

I have two files
j.java: contains a test class with Main
DotNetAppConfigFileMgr.java: contains a prototype Xml DOM wrapper for a project.

I compile using:
javac *.java -classpath C:\_Tmp\Java\Xerces-J-bin.2.9.1.zip

I run using:
java -classpath .;C:\_Tmp\Java\Xerces-J-bin.2.9.1.zip j

In DotNetAppConfigFileMgr.java, if I add the following first line: "package MyPackage", and in j.java I add "import MyPackage.*", it still compiles but does not run, and gives a class not found error. Am I missing an option when I start "java" ?

 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guy:

Are your files in the right directory?

John.
 
Guy Harel
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is in the same directory:

dir C:\_Tmp\Java
.
..
DotNetAppConfigFileMgr.class
DotNetAppConfigFileMgr.java
DotNetAppConfigFileMgrException.class
DotNetAppConfigFileMgrException.java
j.class
j.java
MediSolutionExceptionMgr.class
MediSolutionExceptionMgr.java
Xerces-J-bin.2.9.1.zip
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guy:

That's your problem, then. Packages map to directories, so the package this.is.a.package maps to this/is/a/package, starting on your classpath.

John.
 
Guy Harel
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question turned out to be the answer. I created a sub-directory "MediSolution" and put the files theres now it runs. Thanks.
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guy:

Glad I could help.

John.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done, John. And welcome to JavaRanch, Guy Harel
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic