|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
1. A programmer installs a new library contained in a .jar file. In order to access the library from his code, he sets the CLASSPATH environment variable to point to the new .jar file. Now he finds that he gets an error message when he tries to launch simple applications:
In this case, thejava Hello Exception in thread "main" java.lang.NoClassDefFoundError: HelloHelloclass is compiled into a .class file in the current directory — yet thejavacommand can't seem to find it. What's going wrong?
1. Write an application,
PersistentEcho, with the following features:
- If
PersistentEchois run with command line arguments, it prints out those arguments. It also saves the string printed out to a property, and saves the property to a file calledPersistentEcho.txt- If
PersistentEchois run with no command line arguments, it looks for an environment variable called PERSISTENTECHO. If that variable exists,PersistentEchoprints out its value, and also saves the value in the same way it does for command line arguments.- If
PersistentEchois run with no command line arguments, and the PERSISTENTECHO environment variable is not defined, it retrieves the property value fromPersistentEcho.txtand prints that out.