Discussion:
How to Install Bruce Eckels Annotated Solutions Guide code examples
(too old to reply)
Peter
2008-10-16 15:10:35 UTC
Permalink
I recenlty bought Bruce Eckels book/pdf "Thinking in Java Fourth
Edition" and The Annotated Solutions Guide code examples.
The installation instructions for the code examples are not written
for OS X and that is where the trouble starts..

First the CLASSPATH has to be set to the code examples directory.
I can add the CLASSPATH to the bashrc but decided to add the paths to
the DefaultClassPath in /System/Library/Java/JavaConfig.plist

Then some jar files have to be copied to a created directory,
javassist.jar, swt.jar, tools.jar, javaws.jar, xom.jar, and added to
the CLASSPATH.

So after this the DefaultClassPath looks like this:
Code:
DefaultClasspath = "$HOME/Library/Java:$NEXT_ROOT/Library/Java:
$NEXT_ROOT/System/Library/Java:$NEXT_ROOT/Network/Library/Java:
$NEXT_ROOT/System/Library/Frameworks/JavaVM.framework/Classes/
classes.jar:$NEXT_ROOT/System/Library/Frameworks/JavaVM.framework/
Classes/ui.jar:/Users/peter/Documents/Java\ training/TIJ4-Solutions-
code:/Users/peter/Documents/Java\ training/jars/javassist.jar:/Users/
peter/Documents/Java\ training/jars/javaws.jar:/Users/peter/Documents/
Java\ training/jars/swt.jar:/Users/peter/Documents/Java\ training/jars/
xom-1.1.jar";

Installing ant was easy, so building the code could start using ant...
But it fails

Code:
BUILD FAILED
/Users/peter/Documents/Java training/TIJ4-Solutions-code/build.xml:70:
The following error occurred while executing this line:
/Users/peter/Documents/Java training/TIJ4-Solutions-code/net/build.xml:
68: You must install the Javassist library from http://sourceforge.net/projects/jboss/
I installed the javassist jar file in the same directory as defined in
DefaultClassPath so have no clue what is wrong. Hints / tips ??

Also tools.jar is not available in the JDK installed with OS X
wherefore i have not found a workaround. Does somebody have a
workaround for this ? Or better complete instructions for installing
the code examples from Bruce Eckels Annotated Solution Guide for
Thinking in Java. I cannot imagine that i am the first to install this
on OS X, and googled ont his subject but have not been able to find
any instructions.

Any help is welcome !
Lew
2008-10-16 15:32:21 UTC
Permalink
Post by Peter
I recenlty bought Bruce Eckels book/pdf "Thinking in Java Fourth
Edition" and The Annotated Solutions Guide code examples.
There are better books. He doesn't always exactly do things the Java Way.
Post by Peter
The installation instructions for the code examples are not written
for OS X and that is where the trouble starts..
First the CLASSPATH has to be set to the code examples directory.
Setting the CLASSPATH envar means that every Java program you run will use
that path. This is sometimes all right for study, but for "real" code you
should use the classpath options to the Java program.
Post by Peter
I can add the CLASSPATH to the bashrc but decided to add the paths to
the DefaultClassPath in /System/Library/Java/JavaConfig.plist
I am not familiar with this ".plist" file.

It looks like your 'DefaultClassPath' does not actually change the CLASSPATH
envar. 'DefaultClassPath' is not a standard Java thing. Is it something
specific to OS X?

It's better to set classpaths from inside the Ant build.xml. It's more
portable and reliable.
--
Lew
John B. Matthews
2008-10-16 17:49:53 UTC
Permalink
In article
Post by Peter
I recenlty bought Bruce Eckels book/pdf "Thinking in Java Fourth
Edition" and The Annotated Solutions Guide code examples.
The installation instructions for the code examples are not written
for OS X and that is where the trouble starts.
Alternatively, consider the examples in these highly regarded tutorials:

<http://java.sun.com/docs/books/tutorial/index.html>
<http://www.dickbaldwin.com/>
Post by Peter
First the CLASSPATH has to be set to the code examples directory.
I can add the CLASSPATH to the bashrc but decided to add the paths to
the DefaultClassPath in /System/Library/Java/JavaConfig.plist
[...]

This an extraordinarily bad idea. It will likely break in future
updates. The file JavaConfig.plist is used by the OS to configure such
system properties* as java.class.path and java.library.path.

If you find jars that you really want to use across projects, use one of
the directories defined in the system property java.ext.dirs. For
example, I use /Library/Java/Extensions for a particular combination of
JDBC driver and database.

Otherwise, specify the correct paths in the relevant ant build.xml file.
Post by Peter
Installing ant was easy, so building the code could start using
ant... But it fails
BUILD FAILED
/Users/peter/Documents/Java
training/TIJ4-Solutions-code/build.xml:70: The following error
occurred while executing this line: /Users/peter/Documents/Java
training/TIJ4-Solutions-code/net/build.xml: 68: You must install the
Javassist library from http://sourceforge.net/projects/jboss/ I
installed the javassist jar file in the same directory as defined in
DefaultClassPath so have no clue what is wrong. Hints / tips ??
I've not used JBoss, but perhaps lines 68-70 of the indicated build.xml
file will suggest what's awry. Possibly an OS specific pathname needs to
be changed.

[*]
<code>
import java.io.IOException;

class GetProperties {

public static void main (String[] args) {
boolean completed = false;
try {
System.getProperties().store(System.out, null);
completed = true;
}
catch(IOException e) {
e.printStackTrace();
}
finally {
System.out.println ("Completed: " + completed);
}
}
}
</code>
[...]
--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
Lew
2008-10-16 21:00:45 UTC
Permalink
Post by John B. Matthews
Post by Peter
First the CLASSPATH has to be set to the code examples directory.
I can add the CLASSPATH to the bashrc but decided to add the paths to
the DefaultClassPath in /System/Library/Java/JavaConfig.plist
[...]
This an extraordinarily bad idea. It will likely break in future
updates. The file JavaConfig.plist is used by the OS to configure such
system properties* as java.class.path and java.library.path.
If you find jars that you really want to use across projects, use one of
the directories defined in the system property java.ext.dirs. For
example, I use /Library/Java/Extensions for a particular combination of
JDBC driver and database.
This is good advice *if* you want the JARs to be present in all your Java
projects, every single one of them, effectively making them part of the Java
language itself for that system.

This could have adverse consequences if you try to deploy the same code with,
say, an upgraded version of Java or on a different machine. I've seen this in
practice - in one project, code developed against an IBM JDK for use on
WebSphere depended on the presence of certain IBM JARs in the extensions
directory, making life "interesting" when we tried to run it against a Sun JDK.

It's more reliable to set the classpath for individual runs individually,
especially in Ant-driven runs where you can set it up right in the build.xml.
--
Lew
b***@gmail.com
2015-01-03 18:10:42 UTC
Permalink
http://blog.csdn.net/realizelizijun2013/article/details/39701155

Loading...