BusinessLogicneeds access to
HandyBits(and your boss has waived rights to your personal code so long as you don't mind putting it in the product!)
c:\javafor my examples.
package com.mycompanypackage; import org.mypersonalpackages.util.*;or possibly
package com.mycompanypackage; import org.mypersonalpackages.util.HandyUtil;Some people like using import-on-demand (the first version), others don't. To be honest, it's mainly a matter of laziness. I use import-on-demand because I'm lazy. I realise that it could create incompatibilities if names clash later on, but within the standard Java packages that I use that's not likely to happen very often. (This is partly because I don't do much GUI work. If I were using the
java.utilpackages in the same class, I'd be more careful. I'll try to keep my publicly available source a bit cleaner though. (Don't look yet - I haven't done the cleaning!)
Semaphore.SOME_CONSTANTwhich is a static final primitive/literal String, the value will be embedded in
HandyUtil.class.) There are two ways you could compile everything. Either specify it explicitly:
c:\java> javac -d . com\mycompanypackage\*.java org\mypersonalpackage\util\*.javaor create a list of files and pass that to javac:
c:\java> dir /s /b *.java > srcfiles.txt c:\java> javac -d . @srcfiles.txtNote that you compile from the root directory, and you specify
-d .to tell the compiler to put the classes in a package structure starting at the root too. Some people don't like keeping class and source files together - in that case, you could use
-d classes, although you need to create the
classesdirectory first. (You'll also need to either compile everything each time or put classes on the classpath for the compiler with the
-classpathoption.) Unless you really know what you're doing, I suggest you use the above and make sure you don't have a classpath set. If you must use a classpath for some reason (see my notes on the extension mechanism for ways to avoid this), make sure that
.(the current directory) is on the classpath.
java.lang.NoClassDefFoundError: MyCompanyApp (wrong name: com/mycompanypackage/MyCompanyApp. Hopefully, if you've understood everything above, you won't run into this. It happens if you try to run your code using something like this:
c:\java\com\mycompanypackage> java MyCompanyAppHere's how to avoid it:
c:\java> java com.mycompanypackage.MyCompanyApp
Back to the main page.