Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Compiling and running java programs in packages

  Asked By: Diane    Date: Jul 16    Category: Java    Views: 8406
  

I am facing problems compiling and running classes, I have created in
packages.

I have the following files, in the same package knowledgebase.
All the 3 files have the package call. (package knowledgebase ;)
1. KnowledgeBase.java (main class)
2. MyPanel.java
3. TestPanel.java

The directory structure is: C:\java\KnowledgeBase\knowledgebase\

Query-1:
=========
I am trying to compile and run the classes using

javac -classpath \knowledgebase knowledgebase\KnowledgeBase.java ,

- but it is giving error for all the instances of the other classes:
MyPanel and TestPanel.

I was able to make this work using:
javac -classpath \knowledgebase knowledgebase\*.java

Does anyone know why this is happening, what is the correct way to
compile it.

Query-2:
========
java -classpath \knowledgebase knowledgebase\KnowledgeBase - gives a
runtime exception:
Exception in thread "main" java.lang.NoClassDefFoundError:
KnowledgeBase (wrongname: knowledgebase/KnowledgeBase)
[Loaded java.lang.StackTraceElement from C:\Program
Files\Java\j2re1.4.2_05\lib\
rt.jar]

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Baylen Smith     Answered On: Jul 16

1. Change path to ur cur dir using "cd" command
2. set classpath to all lib files  & dont forgot to
add ur cur dir also "."

set classpath=%classpath%;.;
(or)
set classpath=%classpath%;C:\java\KnowledgeBase;

use the following syntax to compile  & run

syntax:
javac -d <dir_name> <source_name.java>
ex:
javac -d C:\java\KnowledgeBase *.java

syntax:
java <package>.<class_name>
ex:
java knowledgebase.KnowledgeBase

 
Didn't find what you were looking for? Find more on Compiling and running java programs in packages Or get search suggestion and latest updates.




Tagged: