Last fortnight vineela posed a question. Sounded silly in the first go but later found it to be not so silly. She was trying to compile java files from command prompt. Guess what happened. A disaster! Now she is not a run of the mill kind. Only issue was that she was born and brought up in the world of user-friendly IDEs. She never worked with the age old tools "javac" and java. Why should she? When was the last time I used javac? Let me guess, it is nearly four years.
There were three problems she was facing, packing the sources, compiling and running. The next step of packing the sources into directories sounds easy. What about classes? As per the practice, they also need to mimic the file structure. We need to duplicate the directory structure. What about running the app? Run it from the top-level package. Wait... Wait... why are we hurrying? Take a break and breath-in... & out... repeat it 3 times (use for loop!!)
Some references before we start.
http://java.sun.com/docs/books/tutorial/java/package/QandE/packages-answers.html http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html http://www.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Packages.html
Simple Example:
Assuming we know how packages are formed we shall go ahead.
Have a directory called C:\Workarea. Now create three folders called "src", "classes". Under "src" create your package structure.
My source files are: myblog.master.Lord.java, myblog.servant.Gini.java.
There is a correlation between and packages and directory structure.
Under C:\Workarea\src create 3 directories
1.) myblog, 2.) mblog\master, 3.)myblog\servant.
Create the same structure under C:\Workarea\classes. We need to copy java sources to src directory location.
Now copy Lord.java to master and Gini.java to the servant directories. Now come to top directory i.e. C:\Workarea.
Under windows run these commands "dir /s /b *.java > a.txt" and then "javac -sourcepath src -classpath . -d classes @a.txt"
javac essentially takes parameters describing the source location, classpath info and destination where classes are to be saved. @a.txt is the file that contains the locations of .java source files
Bingo...
To run the app from C:\Workarea call "java mainclass"
Reality is a perception. Perceptions are not always based on facts, and are strongly influenced by illusions. Inquisitiveness is hence indispensable
Wednesday, May 23, 2007
Subscribe to:
Post Comments (Atom)
Popular Posts
-
I recently had to come with this data-structure, later I found that google collections has a MapMaker which essentially does the same. Post...
-
This is the way I like to handle events. Note the ease with which the MessageSenders and MessageListeners can be "weaved" using ao...
-
There are times when we face the need to marshall and unmarshall java objects. What better than XML for this! Most programmers can write the...
-
Bananas for the code monkey It is always a good idea to prevent users from doing unwarranted things. Thats the whole idea of client side val...
-
Event bus is a rather simple notion, that is of great aid. Think of a telephone network; to communicate between two ends, one would require ...
Labels
- Programing (13)
- monologues (8)
- Java (7)
- experiences (7)
- ideas (2)
- java script (2)
- CSS (1)
- GXT (1)
- My First Post (1)
- Politics (1)
- movies (1)
About Me
- Swaroop
- Well for a start, I dont' want to!. Yes I am reclusive, no I am not secretive; Candid? Yes; Aspergers? No :). My friends call me an enthusiast, my boss calls me purist, I call myself an explorer, to summarise; just an inquisitive child who didnt'learn to take things for granted. For the sake of living, I work as a S/W engineer. If you dont' know what it means, turn back right now.
No comments:
Post a Comment