by Mahesh Chalil
If you are planning to work with eclipse for Project1, Project 3 and Project 4 here are some points, which might be helpful.
1. Setting up Workspace:
Start Eclipse after downloading and extracting it, double click on the “eclipse.exe” file from eclipse directory [right click on the eclipse.exe and send short cut to desktop]
If you set your workspace to point to one level above the root directory of the project as your workspace directory for eclipse, you will be perfectly fine.
So for example, if your root directory in windows for your cscie259 course is c:\cscie259 and you have project1-x.x, project3-x.x and project4-x.x directories under this directory:
You should set your workspace for eclipse as [c:\cscie259]. Don’t include projectn-x.x in your workspace path where n is the project assignment number. And everything following is assuming that you set your workspace to the root directory where all projects are downloaded, say, c:\cscie259
Once you have your eclipse opened, your workspace is now pointing to c:\cscie259 folder now.
Now, lets set up the java project in eclipse.
File -> New Project -> Java project from existing ant build file
Click on Browse and select the build.xml file, which is under the root directory of each project. [Project1-x.x directory for example]
You can default to the project name which eclipse offered. Now note the point that, your source file location will not be changing. It will be still “src” folder under your main project root directory. For example, c:\cscie259\project1-x.x\src. But eclipse now know everything from the build.xml file.
2. Now to make sure your compiled classes of your project goes to a particular directory:
For project1, set this output directory to project1\bin but for project 3, set this output folder to project3\classes directory, so that you don’t have to manually copy them to webapps/ROOT/WEB-INF/classes directory
Right click on project3-> properties from eclipse
Click on Java Build Path -> Source Tab -> Default Output folder
Click on browse -> Select "classes" folder from the list displayed.
You can do the same step for project 1 too but you can set the output folder to bin instead of classes.
3. Now, to build the projects. By default u should get errors from eclipse because several jars are missing from the build path.
So add all libraries by right clicking on project -> Properties -> Java Build Path
You can add external jars from the different directories as per the project specs to make sure your source files will be compiled.
Say for example, to include all the jar files from xalan_home directory,
Click on add external jars from the build path
Xalan_home/*.jar [You can use CTRL key to select all jars from the open file selection box]
Now for project3, you must get some servlet errors, in order to resolve them, add this jar file:
One more important thing, in project 3 is:
When you change your java classes, tomcat will hot-deploy for us when it sees the class files changed when you build from eclipse, because eclipse is copying your classes to WEB-INF/classes directory same way build file does it for us. That means, you don’t need to restart the tomcat server if you change your java files. In order to make sure that Tomcat hot-deployed your java classes already, you must see this line in tomcat server console, once you build your java classes from eclipse.
If you don’t see this line, your output classes may not be going to the WEB-INF/classes directory, so please make sure you followed the step to set your output folder for your classes as explained in one of the above steps.
Right click inside any java source file and from the menu, Preferences -> General -> Editors ->Text Editor -> Show line numbers
From the main toolbar, Project -> Build Automatically
This once checked, whenever you make any change in the java source file and save it, [CTRL+s] it will automatically build the source file and copy the latest class file to the output folder configured. Note that it will only build the changed source file and not everything.
How to play with source code formatting, adding import statements, organizing import statement, generating constructors, generating getter and setters, adding javadoc etc using eclipse?
Please right click on the java source file -> Source -> select any option which you want to perform. [All are self-explanatory]
In order to add javadoc comment, please select “Generate Element Comment” from the source context menu [Source -> Generate Element Comment]
Right click on the source file -> References -> Workspace
From the Java Project outline view [If you cant see this view, from the main toolbar -> Window -> Show View -> Outline]
Select the method -> References -> Workspace
When you work on a java project, always make sure you are in the Java Perspective, which will by default show the outline view and Tasks view.
Window -> Open Perspective -> Java
How to rename a method or parameter or class so that wherever it is used will be retrofitted automatically?
Right click on the method or class or attribute and select “Refactor -> Rename”, select the appropriate checkboxes to make sure everywhere it will be retrofitted as you intended to do it.
You made some changes and you want to go back to a previous timestamp in your local history maintained by Eclipse?
Right click inside the source file -> Local History -> Select the appropriate choice
When I do the b2b problem, my DATETIME line looks like this:
<DATETIME xmlns:xalan="http://xml.apache.org/xslt" qualifier="SHIP">
I didn't specify a namespace other than what was in the b2b.xsl file originally.
Where is this result coming from, should it be there, and if not, how do I supress it?
You can probably eliminate that by adding
to your xsl:stylesheet element.
What's the detail difference between 'not()' and '!=', at least in this
An excellent question to pose. Note, first, that = and != act more like "contains" and "does not contain" than "equals" and "not equals." Per the spec,
"If both objects to be compared are node-sets, then the comparison [=]
will be true if and only if there is a node in the first node-set and a
node in the second node-set such that the result of performing the
comparison on the string-values of the two nodes is true..."
not(x = y)
actually checks whether there's some element in x that equals some element in y (in terms of their node values)--and then it negates the answer.
This site will be helpful if u want to play with colors.
You can definitely fine-tune your output, though it does take a little
more effort than one might expect, seeing as we're only talking about
whitespace. But prettier printing can be achieved with the help of, e.g.,
xml:space, xsl:strip-space, and xsl:preserve-space.
Don't demand perfection of yourself when it comes to whitespace (so far as Project 2 is concerned)--reasonably neat output is fine. But, if you'd like to master the topic, two helpful articles on point are:
Tip: Control white space in an XSLT style sheet
What You Need to Know About Whitespace in XML
For those curious how to employ extension functions, know that you can
even invoke this method from your stylesheet. E.g., try running the below through xalan (on any or no XML input):
<xsl:stylesheet version="1.0" xmlns:URLEncoder="xalan://java.net.URLEncoder" xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="URLEncoder:encode('http://domain.tld/path with spaces')"/>
New to java, don’t worry, here are some tips which might help you with this project:
- By default for any class there is a default no-arguments constructor, but if you provide any constructor with "arguments, it is your responsibility to provide the no-argument constructor, if you need one.
- If there is no default constructor in the super class and if you try to override [definition below] arguments constructor in your subclass, you will be forced to call the super(arguments); constructor from your subclass. [try it out. Define 1 constructor in your super class with arguments and now try to define the same constructor in your subclass. If you dont do super from ur subclass, there will be compilation errors. But the moment you add a default constructor in your super class, this error will go away.]
2. Inheritance and overriding
If you have a super class [Eg: node] and you want to inherit from this class [eg: Element, Text etc], you just extend from this super class. And you will get access to all "protected and public" methods and attributes from the super class.
Overriding: Means, providing the same method name, same set of arguments and return type in the subclass. Remember overloading is applied to the same class but overriding is applied to the subclass.
Lets say you are not satisfied the method implementation a super class is providing, you could just override the super class implementation just by "overriding the method" in your subclass and provide your own implementation. There will be scenarios where you want to add some more implementation on top of the existing super class implementation. On that case, override the method from super class, add your implementation in this method and then call super.methodName(same arguments);
Keep in mind, there is no limit on adding any number of methods to ur subclass once you inherit. And these methods will not be available to parent class.
Node nodeA = new Element(name);
Now, lets say you added a new method getXXXX() in Element class, do you think with the instance you created above (nodeA) will be able to access this getXXXX method? NO. Why?
Because, nodeA is assigned to parent class Node eventhough reference is pointing to Element class. With nodeA, you can invoke any methods which are defined in class Node. And if these methods in Node are overridden in your subclass Element, when you say nodeA.methodName(), invocation will be fired against Element class.
So how can you then refer to this method getXXXX method in element? In 3 ways:
a) Element nodeA = new Element(name);
b) Node nodeA = new Element(name);
c) by adding the getXXXX method in Node class. [Keep in mind, Node class is untouchable in our case. This is just an example]
Overloading means, in the same class, you are defining methods with same name with different arguments. [Eg: overloaded constructors]
Use List interface and their implementation like ArrayList, LinkedList to keep on add objects a datastructure. This doesnt have a key/value pair but just values are added to a list. You can retrieve them by either using index or by iterating through them using Iterator.
If you are wondering what's the simple difference between an Array, Vector and List, if you are using an Array, you need to define the capacity of the array before even starting to store data in it. But with Vector and List, you dont need to define the capacity before starting to store/add data to it.
You can use Map inteface and their implementation like HashMap, Hashtable to store values using key/value pairs.
You can retrieve the data from this map using get(key) method or iterating through the keys [getKeySet() method returns a Set and iterate through this Set using getKeySet().iterator() and then retrieve the value using map.get(keyName);]
The HashMap class is roughly equivalent to Hashtable, except that HashMap is unsynchronized [not threadsafe] and permits nulls. More details you can get from the API Spec.
XSLT Simple Tutorial.