This content has been marked as final. Show 6 replies
Dayananda B V wrote:You're guessing again, and yet again you're wrong.
c:\Java Programs>javac com.jlc.p1.Test84.java
sigh, I don't like to answer when I can see only one thing was tried and then the stuff was dumped on a forum but now I feel obliged. The command used to compile is wrong, you just do a regular javac Filename.java, even when there are packages in play. The trick is to use a proper folder structure.
Say that your classpath is this:
Our "project" directory is where we are going to store our Java application, with packages. If you have a class "myapp.model.User", so it is a class User in the package myapp.model, you would store it like this:
See how that works? The package directory structure starts in the folder that is part of the classpath. To compile, simply navigate to the model subdirectory and type javac *.java to lazily compile everything in that directory, or pass the specific filename. That will produce a .class file in the same directory. You can make sure that classes are compiled to a different directory, but I wouldn't bother with that when you're still learning; it is best left over to automation tools such as an IDE or ANT/Maven.
Now when you have all your classes neatly compiled in their proper directories you will want to run the application with a package. Lets say we have a class myapp.Main which has a main() function, you can run that with:
Again c:\project is added to the classpath so that Java knows to look there for classes (and classes in packages).
java -cp c:\project myapp.Main