texerasmo
09-06-2004, 14:56
riesco a compilare questa classe java ho importato i miei jar nel classpath ma quando lancio la classe mi da il seguente errore:
C:\j2sdk1.4.2_04\bin>java c:\xslmino\classes\CreaXML provaeramo.txt
Exception in thread "main" java.lang.NoClassDefFoundError: c:\xslmino\classes\Cr
eaXML
ecco la classe java
import java.io.*;
import java.util.*;
/*
IMPORTIAMO I PACKAGE NECESSARI PER
LAVORATE CON GLI XML
/**/
import org.jdom.*;
import org.jdom.output.XMLOutputter;
public class CreaXML
{
public CreaXML(String nomeFile)
{
try
{
writeFile(nomeFile);
}catch(Exception e)
{
System.err.println ("errore: "+e);
}
}
public void writeFile(String path) throws Exception
{
File fileTmp = new File(path);
/*
ISTANZIAMO UN OGGETTO Element
PASSANDOGLI LA STRINGA
CHE SARA' IL NOME DEL NOSTRO SUPERTAG
/**/
Element root = new Element("root");
/*
ISTANZIAMO UN OGGETTO Document
PASSANDOGLI COME PARAMETRO L'OGGETTO
ELEMENT PRECEDENTEMENTE ISTANZIATO
/**/
Document documento = new Document(root);
/*
AGGIUNGIAMO AL NOSTRO ELEMENT UN
ATTRIBUTO:
<root attributo=valore>
/**/
root = root.setAttribute( "attributo","valore");
/*
ISTANZIAMO ALTRI OGGETTI Element
PASSANDOGLI LE STRINGHE
CHE SARANNO I NOMI DEI NOSTRI TAG
/**/
Element initparam = new Element("init-param");
Element paramname = new Element("param-name");
Element paramvalue = new Element("param-value");
/*
ASSEGNAMO DEI VALORI AI
TAG param-name E param-value:
<param-name>mio nome</param-name>
/**/
paramname.addContent("mio nome");
paramvalue.addContent("mio valore");
/*
AGGIUNGIAMO I TAG param-name E
Param-value AL TAG init-param
/**/
initparam.addContent(paramname);
initparam.addContent(paramvalue);
/*
AGGIUNGIAMO IL TAG init-param
AL SUPERTAG root
/**/
root.addContent(initparam);
BufferedWriter out = null;
try
{
out = new BufferedWriter(new FileWriter(path));
/*
ISTANZIAMO LA CLASSE XMLOutputter
CHE CI PERMETTE DI FORMATTARE IL
FILE XML.
/**/
XMLOutputter xout = new XMLOutputter();
xout.setIndent(true);
xout.setNewlines(true);
/*
CON QUESTA ISTRUZIONE SCRIVIAMO
IL DOCUMENTO documento IN UN
BufferedWriter CHE CREA IL FILE
TRAMITE UN FileWriter
/**/
xout.output(documento,out);
}catch (IOException e)
{
System.err.println ("errore: "+e);
}finally
{
try
{
out.close();
}catch(IOException e)
{
System.err.println ("errore: "+e);
}
}
}
public static void main(String args[])
{
CreaXML crea = new CreaXML(args[0]);
}
}
ecco come importo i jar
C:\j2sdk1.4.2_04\bin>set CLASSPATH="c:\xslmino\lib\xerces.jar";c:\xslmino\lib\jd
om.jar;"c:\C:\j2sdk1.4.2_04\bin\";.
C:\j2sdk1.4.2_04\bin>java c:\xslmino\classes\CreaXML provaeramo.txt
Exception in thread "main" java.lang.NoClassDefFoundError: c:\xslmino\classes\Cr
eaXML
ecco la classe java
import java.io.*;
import java.util.*;
/*
IMPORTIAMO I PACKAGE NECESSARI PER
LAVORATE CON GLI XML
/**/
import org.jdom.*;
import org.jdom.output.XMLOutputter;
public class CreaXML
{
public CreaXML(String nomeFile)
{
try
{
writeFile(nomeFile);
}catch(Exception e)
{
System.err.println ("errore: "+e);
}
}
public void writeFile(String path) throws Exception
{
File fileTmp = new File(path);
/*
ISTANZIAMO UN OGGETTO Element
PASSANDOGLI LA STRINGA
CHE SARA' IL NOME DEL NOSTRO SUPERTAG
/**/
Element root = new Element("root");
/*
ISTANZIAMO UN OGGETTO Document
PASSANDOGLI COME PARAMETRO L'OGGETTO
ELEMENT PRECEDENTEMENTE ISTANZIATO
/**/
Document documento = new Document(root);
/*
AGGIUNGIAMO AL NOSTRO ELEMENT UN
ATTRIBUTO:
<root attributo=valore>
/**/
root = root.setAttribute( "attributo","valore");
/*
ISTANZIAMO ALTRI OGGETTI Element
PASSANDOGLI LE STRINGHE
CHE SARANNO I NOMI DEI NOSTRI TAG
/**/
Element initparam = new Element("init-param");
Element paramname = new Element("param-name");
Element paramvalue = new Element("param-value");
/*
ASSEGNAMO DEI VALORI AI
TAG param-name E param-value:
<param-name>mio nome</param-name>
/**/
paramname.addContent("mio nome");
paramvalue.addContent("mio valore");
/*
AGGIUNGIAMO I TAG param-name E
Param-value AL TAG init-param
/**/
initparam.addContent(paramname);
initparam.addContent(paramvalue);
/*
AGGIUNGIAMO IL TAG init-param
AL SUPERTAG root
/**/
root.addContent(initparam);
BufferedWriter out = null;
try
{
out = new BufferedWriter(new FileWriter(path));
/*
ISTANZIAMO LA CLASSE XMLOutputter
CHE CI PERMETTE DI FORMATTARE IL
FILE XML.
/**/
XMLOutputter xout = new XMLOutputter();
xout.setIndent(true);
xout.setNewlines(true);
/*
CON QUESTA ISTRUZIONE SCRIVIAMO
IL DOCUMENTO documento IN UN
BufferedWriter CHE CREA IL FILE
TRAMITE UN FileWriter
/**/
xout.output(documento,out);
}catch (IOException e)
{
System.err.println ("errore: "+e);
}finally
{
try
{
out.close();
}catch(IOException e)
{
System.err.println ("errore: "+e);
}
}
}
public static void main(String args[])
{
CreaXML crea = new CreaXML(args[0]);
}
}
ecco come importo i jar
C:\j2sdk1.4.2_04\bin>set CLASSPATH="c:\xslmino\lib\xerces.jar";c:\xslmino\lib\jd
om.jar;"c:\C:\j2sdk1.4.2_04\bin\";.