Your mathlibrary needs the
and mathpackage doesn't.
Note: Avoid confusing names like 'MathPackage'.
It's you Application, so MathApplication might be a choice - or MathApp.
if you start from dir .../SOME
Let this be the root of your world.
If you create a package, it has to be in a directory of the same name:
If a class Foo claims to be in a package x, it has to be in a directory x.
If class Bar claims to be in x.y it has to be in directory x/y
Note: On Windows, you need falling slashes.
Note: package-names
should be in all lowercase letters (ie.: java.beans.beancontext).
Note: Class-names
should start with uppercase, and use uppercase for combined words repeatedly (ie.: MouseListener).
Note: To access 'Bar', you need:
The example above will still not work, because if you import own or third-party packages, your classes need package-declarations too.
Declare your App to be in the package math, and move it there:
But don't 'cd' to 'math'. We all know, it seems to be easier moving to math, to avoid tipping 'math/' all the time ('edit math/MathApp.java', 'javac math/MathApp.java', '
java math/MathApp') but if you move to 'math', you get short commands and big trash.
source:
For your source code:
- for very small projects (2 - 3 classes) you may mix .java and .class files in the same directory.
- for bigger projects, you make two roots, one for the source, one for the bytecode.
to compile, you simply move to
Note: Avoid moving to x/y/ to compile Bar.java.
It is x.y.Bar, and you have to compile it from .../src .
to pack it into an jar, you move to the PARENT of bin (often: classes)
Splitting source and classes is useful for:
- creating jar's that don't contain the source
- to ship the classes to a customer without the sources
- to backup the sources without the classes
Creating a jar is very useful, since this jar will now be the root of your world, and you may call it from where you want, (if you generated a manifest with the main-class):
.../FAR/far/away> java -jar ../../../A/B/c/Math.jar
Note: It's generally a bad idea, to use the JDK-DIR as source of your classes/ projects/ sources.
If you have:
and get the new j2sdk1.4.2, you probably have to fix a lot of scripts.
---
[ March 31, 2004: Message edited by: Stefan Wagner ]
edited to add a missing hint, minor improvements.
[ April 01, 2004: Message edited by: Stefan Wagner ]