An XSLT processor is probably readily available to you on your computer desktop in the form of a web browser: Microsoft Internet Explorer (IE) Version 6, Netscape Navigator (Netscape) Version 7.1, Mozilla Version 1.4, or Mozilla Firebird 0.7. Each of these browsers has client-side XSLT processing ability already built into them.
The way to apply an XSLT stylesheet like msg.xsl to the document msg.xml in a browser is by using a processing instruction. A processing instruction (PI) allows you to include instructions for an application in an XML document.
You can see a processing instruction in a slightly altered version of msg.xml, which I call msg-pi.xml:
The XML stylesheet PI should always come before the first element in the document (the document element msg in msg-pi.xml). The purpose of this PI is similar to one of the purposes of the link tag in HTML, that is, to associate a stylesheet with the document. Save msg-pi.xml in a text file with the other files. If you open msg-pi.xml in one of the browsers I mentioned, the built-in XSLT processor in the browser will write the string Found it! on the browser's canvas or rendering space.
The Unix commands sudo and su allow access to other commands as a different user.
The sudo command The sudo command stands for "superuser do". It prompts you for your personal password and confirms your request to execute a command by checking a file, called sudoers, which the system administrator configures. Using the sudoers file, system administrators can give certain users or groups access to some or all commands without those users having to know the root password. It also logs all commands and arguments so there is a record of who used it for what, and when.
To use the sudo command, at the command prompt, enter:
sudo command Replace command with the command for which you want to use sudo.
The sudo command also makes it easier to practice the principle of least privilege (PoLP), which is a computer security concept that helps control system access and potential system exploits and compromises. For more information about the sudo command, visit A. P. Lawrence's Using sudo page.
The su command The su command stands for "switch user", and allows you to become another user. To use the su command on a per-command basis, enter:
su user -c command Replace user with the name of the account which you'd like to run the command as, and command with the command you need to run as another user. To switch users before running many commands, enter:
su user Replace user with the name of the account which you'd like to run the commands as.
The user feature is optional; if you don't provide a user, the su command defaults to the root account, which in Unix is the system administrator account. In either case, you'll be prompted for the password associated with the account for which you're trying to run the command. If you supply a user, you will be logged in as that account until you exit it. To do so, press Ctrl-d or type exit at the command prompt.
Using su creates security hazards, is potentially dangerous, and requires more administrative maintenance. It's not good practice to have numerous people knowing and using the root password because when logged in as root, you can do anything to the system. This could provide too much power for inexperienced users, who could unintentionally damage the system. Additionally, each time a user should no longer use the root account (e.g., an employee leaves), the system administrator will have to change the root password.
Secure file transfers to and from local or remote systems can be initiated with the SCP UNIX command.
To use the scp command to copy files between systems, use the following command:
scp filename1 userid@hostname:filename2 where filename1 is the file on the local system that you wish to copy, userid@hostname is the userid and hostname where you wish to copy it, and filename2 is the name you want to call the file on the remote system. For example:
scp myfile jdoe@terpconnect.umd.edu:myfile Note: scp may also be used to copy files from a remote system to a local system. To do this in the first example above, reverse the order of filename1 and userid@hostname:filename2.
When this command is typed on the Glue system, it will copy the file to the TerpConnect system.
When you issue the command, you'll be prompted for the password on the remote system. You will then be given the stats of the transfer. Pay attention to the second item on the stat line; it's how much of the file got transferred (you want to see 100%). For example:
scp myfile jdoe@terpconnect.umd.edu:myfile jdoe@terpconnect.umd.edu's password: myfile 100% |***************************| 1232 00:00 The password will not show up when typed. The statistics indicate the percentage of the file that was transferred, the size of the file, and the estimated time to transfer the file (in this case, immediate). The scp command gives you three chances to get the password right before it aborts the connection.
To use the scp command to copy directories between systems, use the following command:
scp -r directoryname userid@hostname:directoryname2 where directoryname is the directory on the local system you wish to copy, userid@hostname is the userid and hostname where you wish to copy it, and directoryname2 is the name you want to call the file on the remote system. For example:
scp -r mydirectory jdoe@terpconnect.umd.edu:mydirectory Note: scp may also be used to copy directories from a remote system to a local system. To do this in the first example above, reverse the order of directoryname and userid@hostname:directoryname2.
When this command is typed on the Glue system, it will copy the directory and all of its contents to the TerpConnect system.
The most common way to display help is at a UNIX prompt. Before you issue the scp command you can receive help at the UNIX prompt. An on-line UNIX manual is available for detailed help on scp. To access the manual information about scp, type the following at the UNIX system prompt:
If you want to copy the entire database, the basic steps are as follows:
1. Perform a full export:
exp userid=system/manager file=my_db.dmp log=my_db.log full=y The FULL=Y parameter forces a full database export. I also make sure to log the output of my export utility to a log file. It becomes a handy reference. 2. FTP the dump file (and log file) to the destination server. Make sure that you FTP in binary mode!
3. Precreate a new database on the destination server.
4. Precreate the tablespaces on the new database to match the same tablespace names of your source database.
5. Import the full database:
imp userid=system/manager file=my_db.dmp log=imp.log full=y Again, log the output to a file in case there are errors. Copying a schema
If you only want to copy a schema to the new server, things are basically the same.
1. Perform a schema export:
exp userid=system/manager file=my_db.dmp log=my_db.log owner=SCOTT The OWNER parameter exports a schema. In my example, that would be the SCOTT schema. Again, I also make sure to log the output of my export utility to a log file. 2. FTP the dump file (and log file) to the destination server. Make sure that you FTP in binary mode!
3. Precreate a new database on the destination server.
4. Precreate the tablespaces on the new database to match the same tablespace names of your source database.
5. Precreate the user in that database.
6. Import the dump file:
imp userid=system/manager file=my_db.dmp log=imp.log fromuser=SCOTT Again, log the output to a file in case there are errors. The FROMUSER clause tells imp which schema to import. If you wish to change the objects to a new owner, use the TOUSER clause as well.
Ant's buildfiles are written in XML. Each buildfile contains one project
and at least one (default) target. Targets contain task elements.
Each task element of the buildfile can have an id attribute and
can later be referred to by the value supplied to this. The value has
to be unique. (For additional information, see the
Tasks section below.)
the default target to use when no target is supplied.
No; however, since Ant 1.6.0,
every project includes an implicit target that contains any and
all top-level tasks and/or types. This target will always be
executed as part of the project's initialization, even when Ant is
run with the -projecthelp option.
basedir
the base directory from which all path calculations are
done. This attribute might be overridden by setting
the "basedir"
property beforehand. When this is done, it must be omitted in the
project tag. If neither the attribute nor the property have
been set, the parent directory of the buildfile will be used.
No
Optionally, a description for the project can be provided as a
top-level <description> element (see the href="CoreTypes/description.html">description type).
Each project defines one or more targets.
A target is a set of tasks you want
to be executed. When starting Ant, you can select which target(s) you
want to have executed. When no target is given,
the project's default is used.
A target can depend on other targets. You might have a target for compiling,
for example, and a target for creating a distributable. You can only build a
distributable when you have compiled first, so the distribute target
depends on the compile target. Ant resolves these dependencies.
It should be noted, however, that Ant's depends attribute
only specifies the order in which targets should be executed - it
does not affect whether the target that specifies the dependency(s) gets
executed if the dependent target(s) did not (need to) run.
More information can be found in the
dedicated manual page.
A task can have multiple attributes (or arguments, if you prefer). The value
of an attribute might contain references to a property. These references will be
resolved before the task is executed.
All tasks share a task name attribute. The value of
this attribute will be used in the logging messages generated by
Ant.
Tasks can be assigned an id attribute:
<taskname id="taskID" ... />
where taskname is the name of the task, and taskID is
a unique identifier for this task.
You can refer to the
corresponding task object in scripts or other tasks via this name.
For example, in scripts you could do:
<script ... >
task1.setFoo("bar");
</script>
to set the foo attribute of this particular task instance.
In another task (written in Java), you can access the instance via
project.getReference("task1").
Note1: If "task1" has not been run yet, then
it has not been configured (ie., no attributes have been set), and if it is
going to be configured later, anything you've done to the instance may
be overwritten.
Note2: Future versions of Ant will most likely not be backward-compatible with this behaviour, since there will likely be no
task instances at all, only proxies.
Properties are an important way to customize a build process or
to just provide shortcuts for strings that are used repeatedly
inside a build file.
In its most simple form properties are defined in the build file
(for example by the property task) or might be set outside Ant. A property has a name and a
value; the name is case-sensitive. Properties may be used in the
value of task attributes or in the nested text of tasks that support
them. This is done by placing the property name between
"${" and "}" in the
attribute value. For example, if there is a "builddir"
property with the value "build", then this could be used
in an attribute like this: ${builddir}/classes. This
is resolved at run-time as build/classes.
With Ant 1.8.0 property expansion has become much more powerful
than simple key value pairs, more details can be
found in the concepts section of this
manual.
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
Notice that we are declaring properties outside any target. As of
Ant 1.6 all tasks can be declared outside targets (earlier version
only allowed <property>,<typedef> and
<taskdef>). When you do this they are evaluated before
any targets are executed. Some tasks will generate build failures if
they are used outside of targets as they may cause infinite loops
otherwise (<antcall> for example).
We have given some targets descriptions; this causes the projecthelp invocation option to list them as public targets with the descriptions; the
other target is internal and not listed.
Finally, for this target to work the source in the src subdirectory
should be stored in a directory tree which matches the package names. Check the
<javac> task for details.
A project can have a set of tokens that might be automatically expanded if
found when a file is copied, when the filtering-copy behavior is selected in the
tasks that support this. These might be set in the buildfile
by the filter task.
Since this can potentially be a very harmful behavior,
the tokens in the files must be of the form @token@, where
token is the token name that is set
in the <filter> task. This token syntax matches the syntax of other build systems
that perform such filtering and remains sufficiently orthogonal to most
programming and scripting languages, as well as with documentation systems.
Note: If a token with the format @token@ is found in a file, but no
filter is associated with that token, no changes take place;
therefore, no escaping
method is available - but as long as you choose appropriate names for your
tokens, this should not cause problems.
Warning: If you copy binary files with filtering turned on, you can corrupt the
files. This feature should be used with text files only.
You can specify PATH- and CLASSPATH-type
references using both
":" and ";" as separator
characters. Ant will
convert the separator to the correct character of the current operating
system.
Wherever path-like values need to be specified, a nested element can
be used. This takes the general form of:
The location attribute specifies a single file or
directory relative to the project's base directory (or an absolute
filename), while the path attribute accepts colon-
or semicolon-separated lists of locations. The path attribute is intended to be used with predefined paths - in any other
case, multiple elements with location attributes should be
preferred.
As a shortcut, the <classpath> tag
supports path and
location attributes of its own, so:
In addition, one or more
Resource Collections
can be specified as nested elements (these must consist of
file-type resources only).
Additionally, it should be noted that although resource collections are
processed in the order encountered, certain resource collection types
such as fileset,
dirset and
files are undefined in terms of order.
This builds a path that holds the value of ${classpath},
followed by all jar files in the lib directory,
the classes directory, all directories named
classes under the apps subdirectory of
${build.dir}, except those
that have the text Test in their name, and
the files specified in the referenced FileList.
If you want to use the same path-like structure for several tasks,
you can define them with a <path> element at the
same level as targets, and reference them via their
id attribute--see References for an
example.
By default a path like structure will re-evaluate all nested
resource collections whenever it is used, which may lead to
unnecessary re-scanning of the filesystem. Since Ant 1.8.0 path has
an optional cache attribute, if it is set to true, the path
instance will only scan its nested resource collections once and
assume it doesn't change during the build anymore (the default
for cache still is false). Even if you are using the
path only in a single task it may improve overall performance to set
cache to true if you are using complex nested
constructs.
A path-like structure can include a reference to another path-like
structure (a path being itself a resource collection)
via nested <path> elements:
In Ant 1.6 a shortcut for converting paths to OS specific strings
in properties has been added. One can use the expression
${toString:pathreference} to convert a path element
reference to a string that can be used for a path argument.
For example:
Several tasks take arguments that will be passed to another
process on the command line. To make it easier to specify arguments
that contain space characters, nested arg elements can be used.
Attribute
Description
Required
value
a single command-line argument; can contain space
characters.
Exactly one of these.
file
The name of a file as a single command-line
argument; will be replaced with the absolute filename of the file.
path
A string that will be treated as a path-like
string as a single command-line argument; you can use ; or : as
path separators and Ant will convert it to the platform's local
conventions.
pathref
Reference to a path
defined elsewhere. Ant will convert it to the platform's local
conventions.
line
a space-delimited list of command-line arguments.
prefix
A fixed string to be placed in front of the
argument. In the case of a line broken into parts, it will be
placed in front of every part. Since Ant 1.8.
No
suffix
A fixed string to be placed immediately after the
argument. In the case of a line broken into parts, it will be
placed after every part. Since Ant 1.8.
No
It is highly recommended to avoid the line version
when possible. Ant will try to split the command line in a way
similar to what a (Unix) shell would do, but may create something that
is very different from what you expect under some circumstances.
Examples
<arg value="-l -a"/>
is a single command-line argument containing a space character,
not separate commands "-l" and "-a".
<arg line="-l -a"/>
This is a command line with two separate arguments, "-l" and "-a".
<arg path="/dir;/dir2:\dir3"/>
is a single command-line argument with the value
\dir;\dir2;\dir3 on DOS-based systems and
/dir:/dir2:/dir3 on Unix-like systems.
Any project element can be assigned an identifier using its
id attribute. In most cases the element can subsequently
be referenced by specifying the refid attribute on an
element of the same type. This can be useful if you are going to
replicate the same snippet of XML over and over again--using a
<classpath> structure more than once, for example.
All tasks that use nested elements for
PatternSets,
FileSets,
ZipFileSets or
path-like structures accept references to these structures
as shown in the examples. Using refid on a task will ordinarily
have the same effect (referencing a task already declared), but the user
should be aware that the interpretation of this attribute is dependent on the
implementation of the element upon which it is specified. Some tasks (the
property task is a handy example)
deliberately assign a different meaning to refid.
Ant supports a plugin mechanism for using third party tasks. For using them you
have to do two steps:
place their implementation somewhere where Ant can find them
declare them.
Don't add anything to the CLASSPATH environment variable - this is often the
reason for very obscure errors. Use Ant's own mechanisms for adding libraries:
via command line argument -lib
adding to ${user.home}/.ant/lib
adding to ${ant.home}/lib
For the declaration there are several ways:
declare a single task per using instruction using
<taskdef name="taskname"
classname="ImplementationClass"/>
This document provides a step by step tutorial for starting java programming with Ant.
It does not contain deeper knowledge about Java or Ant. This tutorial has the goal
to let you see, how to do the easiest steps in Ant.
We want to separate the source from the generated files, so our java source files will
be in src folder. All generated files should be under build, and there
splitted into several subdirectories for the individual steps: classes for our compiled
files and jar for our own JAR-file.
We have to create only the src directory. (Because I am working on Windows, here is
the win-syntax - translate to your shell):
md src
The following simple Java class just prints a fixed message out to STDOUT,
so just write this code into src\oata\HelloWorld.java.
package oata;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Creating a jar-file is not very difficult. But creating a startable jar-file needs more steps: create a
manifest-file containing the start class, creating the target directory and archiving the files.
Note: Do not have blanks around the >-sign in the echo Main-Class instruction because it would
falsify it!
Four steps to a running application
After finishing the java-only step we have to think about our build process. We have to compile our code, otherwise we couldn't
start the program. Oh - "start" - yes, we could provide a target for that. We should package our application.
Now it's only one class - but if you want to provide a download, no one would download several hundreds files ...
(think about a complex Swing GUI - so let us create a jar file. A startable jar file would be nice ... And it's a
good practise to have a "clean" target, which deletes all the generated stuff. Many failures could be solved just
by a "clean build".
By default Ant uses build.xml as the name for a buildfile, so our .\build.xml would be:
Now we have a working buildfile we could do some enhancements: many time you are referencing the
same directories, main-class and jar-name are hard coded, and while invocation you have to remember
the right order of build steps.
The first and second point would be addressed with properties, the third with a special property - an attribute
of the <project>-tag and the fourth problem can be solved using dependencies.
compile:
[mkdir] Created dir: C:\...\build\classes
[javac] Compiling 1 source file to C:\...\build\classes
jar:
[mkdir] Created dir: C:\...\build\jar
[jar] Building jar: C:\...\build\jar\HelloWorld.jar
run:
[java] Hello World
main:
BUILD SUCCESSFUL
Using external libraries
Somehow told us not to use syso-statements. For log-Statements we should use a Logging-API - customizable on a high
degree (including switching off during usual life (= not development) execution). We use Log4J for that, because
it is not part of the JDK (1.4+) and we want to show how to use external libs
it can run under JDK 1.2 (as Ant)
it's highly configurable
it's from Apache ;-)
We store our external libraries in a new directory lib. Log4J can be
downloaded [1] from Logging's Homepage.
Create the lib directory and extract the log4j-1.2.9.jar into that lib-directory. After that we have to modify
our java source to use that library and our buildfile so that this library could be accessed during compilation and run.
Working with Log4J is documented inside its manual. Here we use the MyApp-example from the
Short Manual [2]. First we have to modify the java source to
use the logging framework:
public class HelloWorld {
static Logger logger = Logger.getLogger(HelloWorld.class);
public static void main(String[] args) {
BasicConfigurator.configure(); logger.info("Hello World"); // the old SysO-statement
}
}
Most of the modifications are "framework overhead" which has to be done once. The blue line is our "old System-out"
statement.
Don't try to run ant - you will only get lot of compiler errors. Log4J is not inside the classpath so we have
to do a little work here. But do not change the CLASSPATH environment variable! This is only for this project and maybe
you would break other environments (this is one of the most famous mistakes when working with Ant). We introduce Log4J
(or to be more precise: all libraries (jar-files) which are somewhere under .\lib) into our buildfile:
In this example we start our application not via its Main-Class manifest-attribute, because we could not provide
a jarname and a classpath. So add our class in the red line to the already defined path and start as usual. Running
ant would give (after the usual compile stuff):
[java] 0 [main] INFO oata.HelloWorld - Hello World
What's that?
[java] Ant task running at the moment
0 sorry don't know - some Log4J stuff
[main] the running thread from our application
INFO log level of that statement
oata.HelloWorld source of that statement
- separator
Hello World the message
For another layout ... have a look inside Log4J's documentation about using other PatternLayout's.
We reuse the path to our own jar file as defined in run-target by giving it an ID.
The printsummary=yes lets us see more detailed information than just a "FAILED" or "PASSED" message.
How much tests failed? Some errors? Printsummary lets us know. The classpath is set up to find our classes.
To run tests the batchtest here is used, so you could easily add more test classes in the future just
by naming them *Test.java. This is a common naming scheme.
We can also produce a report. Something that you (and other) could read after closing the shell ....
There are two steps: 1. let <junit> log the information and 2. convert these to something readable (browsable).
Because we would produce a lot of files and these files would be written to the current directory by default,
we define a report directory, create it before running the junit and redirect the logging to it. The log format
is XML so junitreport could parse it. In a second target junitreport should create a browsable
HTML-report for all generated xml-log files in the report directory. Now you can open the ${report.dir}\index.html and
see the result (looks something like JavaDoc).
Personally I use two different targets for junit and junitreport. Generating the HTML report needs some time and you dont
need the HTML report just for testing, e.g. if you are fixing an error or a integration server is doing a job.