Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

package/directory management & deployment, etc. 2

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo - I've read a couple of books on Java (but no real practical experience, as yet), but don't seem to have absorbed the details on package/directory management, and how these are deployed.
What I need to know is, where would I put the files for my packages & classes in relation to each other & in relation to the Java runtime when deploying an application/applet?
And what else might I need to include in a deployment (3rd party classes?)
I really have no idea of what gets compiled & included & what needs to be looked up at runtime, etc., which makes getting started very difficult!
Sorry if I'm being really obtuse & thanks for any pointers anyone can give me,
doug.

If I had a hammer...
 
I would normally have a directory for my 'project' containing a src subdirectory (for the source files) and a classes subdirectory (for the compiled class files and resources).
The package directories are constructed beneath 'src' and when you compile everything this will be replicatied automatically under the 'classes' directory.

From command-line, you'd compile with something like:-
Code:
javac -sourcepath <path\to\src_directory> -d <path\to\classes_directory> -classpath <any required libraries>

The javac and java commands should know where the JDK and runtime libs are if installed properly.

Tim
 
Thanks alot, Tim.
Does this mean that the compiler would create the same directory structures automatically for the *.class files?
And would I then simply need to place this structure any place I wanted to use it?
& thanks again,
doug.

If I had a hammer...
 
Yes, the structure is created automatically.
To use it you just need to point to the classes directory from your classpath.
Code:
java -cp <path\to\classes_directory> fully.qualified.class.name
where the fully.qualified.class.name is the full package + class name of your main class.

Tim
 
Thanks again for that. Do you know where there is any documentation of this kind of this that I could read up on?
Like I say, everything I've read seems to either assume you know this stuff, or I'm considerably dumberer than the articles'/books' demographic.
(I actually strongly suspect the latter...)
& thanks very much again,
doug.

If I had a hammer...
 
I don't agree.

I imagine tim is using Eclipse, so the directory tree structure is managed by the IDE, but if you don't use an IDE (or you use a different one), that can vary.

Furthermore, by deafult the java compiler compiles files one by one and leaves the .class in the same directory as the .java file.

Maybe you should take a look at compiler options:

Cheers,

Dian
 
Mmmm. I've used JBuilder / Eclipse and Ant to compile stuff. Dian is probably correct about the bog-standard javac command. I stopped using it directly years ago.

At the very least I'd recommend using Ant to manage your projects.

Tim
 
It's actually in Eclipse that I'm learning Java.
However, nothing anywhere else seemed to give me the best-practice sort of advice I needed - the structure you suggest seems sensible.
My concern really is not understanding the details behind what gets compiled & included & what needs to be loaded when run, etc.

If I had a hammer...
 
Well, in Eclipse, when creating projects, choose the 'Create separate source and output folders' option. This gives you a <project_dir>/src and a <project_dir>/bin. The bin directory is where the classes will end up. Rename it to 'classes' if you want, it doesn't really matter.
There is a tab on the wizard called 'Libraries' and you can add any extra API Libraries etc in at this stage if you know them. They will automatically be placed on the classpath when running your project.

Tim
 
Thanks again, man -- and thanks Dian for the javac info!
doug.

If I had a hammer...
 
Other sub-directories you could have in your project:-
a 'lib' directory where you could keep all the 3rd party jars needed for your project.
a 'dist' directory where you place your project's compiled classes and resources packaged as a distributable jar.
a 'doc' folder to hold the generated javadoc which you'll lovingly create for all your java classes.

Tim
 
I generally have something along the lines of
bin - class files (my compiled code -- byte code) and batch file/shellscript (to call java to run the program)
src - the java files and pre-processed stuff
doc - has my documentation on use of programs and the auto generated javadoc (as a subdirectory)

and I use a makefile like:
Code:
all: clean build doc
superall: superClean build doc

#Build Section
build:
	javac -source 1.4 *.java util/*.java net/*.java patrons/*.java command/*.java appt/*.java games/*.java -d ../bin/

#Documentation Section
doc:
	javadoc -tag param -tag return -tag throws -tag gm.todo:a:"To Do:" -tag see -linksource -link [URL unfurl="true"]http://java.sun.com/j2se/1.4.1/docs/api/[/URL] -breakiterator -source 1.4 -stylesheetfile style.css patrons util net appt command games -d ../doc/javaDoc

#Test

#clean
clean:
	rm -f *~ patrons/*~ net/*~ util/*~ games/*~

superClean:
	rm -f *~ patrons/*~ net/*~ util/*~ games/*~
	rm -rf ../doc/javaDoc/*
	rm -rf ../bin/*

I typically use RCS or CVS and have a make rule for checking out and checking in various parts of the project.
 
Please, anybody, help me to understand how these things work in NetBeans(v. 3.6).

I want to crate a package named ESD.
What I understood I can do from NetBeans guide is to create a directory "ESD". Than I create a new project called ESD in NetBeans. I mount directory ESD. Than I point to this directoy in the mounted filesystem and by right click I chose to create new package, which I name "EvalSD". After that the subdirectory of ESD EvalSD is created.

Then I close NetBeans, put my .java files to ..\ESD\EvalSD and in the beginning of each file I have "package ESD.EvalSD" string.

Than I open NetBeans again, I see all that files in the right place, and by right click I select "Tools->Add to project", and for one of them "Tools -> Set as project main class" for each of them.

However, something is wrong. I try to compile, and it doesn't find some of the .class files corresponging to .java files in my package.

PLEASE! Let me know, what is the RIGHT way, as 1-2-3 steps.
 
yes, I have solved the problem. I had to create the new project main class. Then it demonstrated, the correct way was to write "package EvalSD;", not "package ESD.EvalSD;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top