The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by tedweitz]

Oh,

The batch file works with these changes

java -cp jabber.jar;server.jar;../../lib/xerces.jar;../classes
com.metamech.vorpal.Server
import-bot (20211) [Avatar] Offline
#2
[Originally posted by tedweitz]

First off let me thank you Iain for a super great book.

I picked up the book yesterday and found it very clear. The book has a good
flow, it is easy to comprehend while it keeps you engaged.

I hope by the end of the weekend to have my first IM project done from what I
am learning from it.

As for the bleeding edge:

I had a learning experience building the source code so here is how I finely
got around the classpath and the JDK 1.4 xerces issue.

As for the classpath: I usually try to keep it clean, just with a dot,
avoiding ever-changing long path statements.

I use Java JDK 1.4 so I had compilation collisions even after I placed the
downloaded previous xerces in the lib directory.

To solve all these I edited the ant build files

At the top of each file I added the following statement

<project name="jabber" default="test" basedir=".">
<property name="version" value="1.0"/>

<property environment="env"/>

<path id="third-party-jars">
<pathelement path="../lib/xerces.jar"/>
<pathelement path="${env.JUNIT_HOME}/junit.jar"/>
</path>

At the compile call below it I added the reference to these files as follows

<target name="compile">
<mkdir dir="classes"/>

<!-- First compile the source -->
<javac srcdir="src">
destdir="classes"
excludes="**/*.*ml"
debug="${c.debug.on}"
deprecation="${c.depreciation.on}"
optimize="${c.optimize.on}" >

<classpath refid="third-party-jars"/>

</javac>
</target>

I added the JUNIT_HOME to my environment.

To avoid regenerating the docs every time I changed the call at the top of the
initial build file as follows

<!-- ===================================================================== -->
<!-- Ultra simple Ant build file -->
<!-- ===================================================================== -->

<project name="build-all" default="compile" basedir=".">


Hopefully you will find it helpful,

Thanks again for a great book.

Ted
import-bot (20211) [Avatar] Offline
#3
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iain.shigeoka]

> First off let me thank you Iain for a super great book.

Thanks! I'm so glad you are finding it useful.

[Ant script changes]
> Hopefully you will find it helpful,

Yes very. Thanks!

Unfortunately, now is a very shifty time to be doing XML in Java for widely
deployable code. smilie Especially XMPP/Jabber which sort of stretches the use of
XML in a new direction. I'm still very unhappy with the workaround in Xerces
in the first place. Anyhow, thanks for the fix.

-iain
import-bot (20211) [Avatar] Offline
#4
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iamstyles]


Hi:

I think the book was well written and I'm happy that I've got all this code.

My problem is: how do I compile all this and get it working?

I read the Ant installation guide and am completely baffled, I have no
excecutable for build. I've followed the instructions as closely as possible,
but I don't have Ant up and going and every web search for help I get I always
find the same thing: the same old Apache document.

Also, I'm more of a hardware guy rather than a software guy. Is there a top
level overview of what Ant / JUnit really does? That would be really helpful.

Thanks,

J!
import-bot (20211) [Avatar] Offline
#5
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iain.shigeoka]

> Also, I'm more of a hardware guy rather than a software guy. Is there a top
> level overview of what Ant / JUnit really does? That would be really
helpful.

Ant is a build tool and does the same job as 'make' does. It helps to automate
building software using build scripts. Ant, being a next generation make
system, is more powerful, especially with respect to making Java software.

JUnit is a testing framework. It helps to automate the unit testing of
software components (in our case, I use it to automate testing of Java
classes).

If you download and install Ant properly, you should be able to go into the
distribution directory of the chapter source code (the first one you unzipped
that contains a build.xml file) and type 'ant'. All the source code from the
book will then be built automatically.

typing 'ant -projecthelp' in any directory with a build.xml file will print a
list of the ant tasks you can run. For example, most will have the 'compile'
task which will compile the source code associated with that build file. To
run that task, type 'ant compile' to choose that task to run.

Almost all open source Java software I'm aware of uses Ant and JUnit for
building and testing so it's worth installing and learning how this software
works. You'll be running into it in the future, outside of the book source
code. If you learn best from books (I do) then I highly recommend Java
Development with Ant (Hatcher, Loughran), a new Manning book dedicated to
covering Ant inside and out (with an entire chapter on JUnit). Even if you
don't want to buy the book, going to your local book store and reading the
first chapter will give you a good grounding in the tool.

Hope this helps

-iain
import-bot (20211) [Avatar] Offline
#6
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iamstyles]

> > Also, I'm more of a hardware guy rather than a software guy. Is there a top
> > level overview of what Ant / JUnit really does? That would be really
> helpful.
>
> If you download and install Ant properly, you should be able to go into the
> distribution directory of the chapter source code (the first one you unzipped
> that contains a build.xml file) and type 'ant'. All the source code from the
> book will then be built automatically.

Iain:

Thanks for getting back to me. Maybe I'll go buy a book on Ant, I've also
discovered the JMS stuff from Sun and now that I've actually figured out what
a Classpath actually is I have been able to get some of the JMS stuff to
compile but I don't think it's as worthwhile reinventing the wheel with the
Sun stuff as trying to get things in your book working.

I can understand the value of a make tool. I've had a brutal time installing
Ant however. From the apache.org page on the installation I get up to the
command

build -Ddist.dir=<path> dist

And I get nothing from this. I've set my ANT_HOME, JAVA_HOME, PATH and i've
made sure that windows has enough environment space to run. Is there
something other than the Ant-1.5.3 zip file that i'm supposed to have or to
compile somewhere?

Thanks,

J!
import-bot (20211) [Avatar] Offline
#7
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iain.shigeoka]

> I can understand the value of a make tool. I've had a brutal time installing
> Ant however. From the apache.org page on the installation I get up to the
> command
>
> build -Ddist.dir=<path> dist
>
> And I get nothing from this. I've set my ANT_HOME, JAVA_HOME, PATH and i've
> made sure that windows has enough environment space to run. Is there
> something other than the Ant-1.5.3 zip file that i'm supposed to have or to
> compile somewhere?

Wow. Normally Ant is pretty easy to use. Here's my short install guide that
works for me pretty well (I assume you're on Windows).

a) Download the latest ant release from http://jakarta.apache.org
b) Unzip it into a relatively short directory... I suggest c:in on Windows.
This should create a directory c:injakarta-ant-version with all the actual
files in there. Let's call that dir antHome.
c) Now open up the environmental variable settings. On Win2k and XP (and
probably 98/ME) right click on the "My Computer" icon on your desktop and
choose "Properties..." from the pop up menu. Or go to the Start menu and
select Settings | Control Panel | System. Select the "Advanced" tab and click
on the "Environmental Variables" button on the panel. On the top of the
environmental variables dialag box are "Environment for x" where x is your
user name. If there is already an environmental variable up there called
"PATH" then click on it and select "Edit" otherwise, click on "New" and make a
variable called "PATH" (without the quotes). If you're creating a new one,
just add the path to anthome/bin. If there are already existing path entries,
add antHome/bin to the end with a ';' separating it from the previous path.
For example my path has "c:devinjakarta-ant-1.5in". Also check to see if
either the system or your user environmental variables have an entry for
JAVE_HOME. If not, add one as a user environmental variable and point it to
the root of your jdk install. For example mine is "c:j2sdk1.4.1". Click on
"OK" on all the dialogs so they go away. Notice that is all the environmental
variables you should set. If you have set ANT_HOME, remove it. The ant scripts
in antHome/bin take care of that.
d) Test the installation. Open a command prompt and type "ant -version" it
should print a banner reporting version information. For example mine says:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Csmilieocuments and Settingsion>ant -version
Apache Ant version 1.5.2 compiled on February 28 2003
Csmilieocuments and Settingsion>

If you have that you're ready to rock and roll. cd to the directory where you
installed the source code, and type 'ant' and the magic should begin. smilie If
not, then you haven't installer one of the two environmental variables
correctly.

To test your JAVA_HOME variable type the following '%JAVA_HOME%injar' and
you should see the jar command print it's help banner:

Csmilieocuments and Settingsion>%JAVA_HOME%injar
Usage: jar {ctxu}[vfm0Mi] [jar-file] [manifest-file] [-C dir] files ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-0 store only; use no ZIP compression
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name and the archive file name needs to be specified
in the same order the 'm' and 'f' flags are specified.

Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .


Csmilieocuments and Settingsion>

If you don't see that, then JAVA_HOME isn't set to the right spot.

Hope this helps.

-iain
import-bot (20211) [Avatar] Offline
#8
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iamstyles]

Iain:

The newest run i've taken at all this on my Win98 machine (no setting of
environment vars through control panels, I did it all in the Dos prompt window).
I redownloaded just to make sure i got the right file, put it on a short
path to unzip. (C:jakarta-ant-1.5.3)

I did up the PATH addition. (C:jakarta-ant-1.5.3in) Doing ant -version
after that got me:

ANT_HOME is set incorrectly or ant could not be loaded. Please set ANT_HOME.

So, I set ANT_HOME to be C:jakarta-ant-1.5.3. Then when running ant I get:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/tools/ant/Main.

I can confirm my JAVA_HOME since my execution of jar gets the same banner as
you do. Any ideas? I think i'm really close.

J!
import-bot (20211) [Avatar] Offline
#9
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iamstyles]

Iain:

Ant is good to go. Thanks a lot, I was almost going to break down and spend a
fair bit of cash on an Ant book (which I oneday might do).

I'm trying the build for Chapter 2 right now. I've set my classpath to
basically point to ~/jim_src/chp2 so that I can pick up the stuff in
~/jim_src/chp2/com/metamech/jabber but i'm seeing a whole pile of:

rJabberIDTest.java:34:Cannot resolve symbol
[javac] symbol: method assertTrue (java.lang.String.boolean)
[javac] location: class com.metamech.jabber.JabberIDTest

Do I need some fine-tuning on my classpath?

J!
import-bot (20211) [Avatar] Offline
#10
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iain.shigeoka]

> I did up the PATH addition. (C:jakarta-ant-1.5.3in) Doing ant -version
> after that got me:
>
> ANT_HOME is set incorrectly or ant could not be loaded. Please set ANT_HOME.
>
> So, I set ANT_HOME to be C:jakarta-ant-1.5.3. Then when running ant I get:

Aha! Windows 9x kinda sucks because the path must use short filenames rather
than long ones. This is a problem with the os commandline so can't be helped.
You have two options:

1) make sure every directory on the way to ant is shorter than 8 characters
(jakarta-ant-1.5.3 is too long). Rename directories to make them fit.

2) or run a dir and find out what the short name is and use that in your
environmental variable settings (probabl something like jakart~1).

Once you have that set, you shouldn't need to set the ANT_HOME variable
because the ant.bat script does that for you. And you should be able to run
profitably.

-iain
import-bot (20211) [Avatar] Offline
#11
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iain.shigeoka]

Glad you were able to get things going. Let me know if you need any more help.

-iain
import-bot (20211) [Avatar] Offline
#12
Re: Making it all compile - avoiding xerces problems and setting the classpath
[Originally posted by iamstyles]

Iain:

I've been able to get JUnit up and working as well, so I've been able to do a
build with ant on the chapter 2 material. I'm still tripping over a few
Xerces problems with Chp 3 but i'm down to only 1 build error when doing the
compile. I should be fine in the short-term, I've probably got a few
architectural questions to ask once I get all the code up and going.

Thanks for all your help,

J!