• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marshaller Example with Castor

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried to execute sample program using castor( tried with version 1.2.1.1 and 1.3.x)

My Java Stuff:
-------------------------------------------
1. CD.java
------------------------------------------
import java.util.ArrayList;
import java.util.List;

/** A class to represent CDs */
public class CD implements java.io.Serializable {

/** The name of the CD */
private String name = null;

/** The artist of the CD */
private String artist = null;

/** Track listings */
private List tracks = null;

/** Required no-args constructor */
public CD() {
super();
}

/** Create a new CD */
public CD(String name, String artist) {
super();
this.name = name;
this.artist = artist;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setArtist(String artist) {
this.artist = artist;
}

public String getArtist() {
return artist;
}

public void setTracks(List tracks) {
this.tracks = tracks;
}

public List getTracks() {
return tracks;
}

public void addTrack(String trackName) {
if (tracks == null) {
tracks = new ArrayList();
}
tracks.add(trackName);
}
}
--------------------------------------------------------------------

2. MarshalTester
--------------------------------------------------------------------
import java.io.FileWriter;

import org.exolab.castor.xml.Marshaller;

public class MarshalTester {

public static void main(String[] args) {
try {
CD sessions = new CD("Sessions for Robert J", "Eric Clapton");
sessions.addTrack("Little Queen of Spades");
sessions.addTrack("Terraplane Blues");

FileWriter writer = new FileWriter("cds.xml");
Marshaller.marshal(sessions, writer);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace(System.err);
}
}
}

---------------------------------------------
3. My Batch File:
---------------------------------------------
@echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
set CASTOR_JAR=C:\…\My Documents\...\castor 1.1.2.1\castor-1.1.2.1.jar
set PATH=%PATH%;%CASTOR_JAR%;%JAVA_HOME%\bin

cd C:\...\My Documents\...\castor\castor-1.3.1\
javac -d . *.java
----------------------------------------------------------------------------------

I am getting following Exception when I am running my batch file
----------------------------------------------------------------------------------------
MarshalTester.java:3: package org.exolab.castor.xml does not exist
import org.exolab.castor.xml.Marshaller;
^
UnmarshalTester.java:5: package org.exolab.castor.xml does not exist
import org.exolab.castor.xml.Unmarshaller;
^
MarshalTester.java:14: cannot find symbol
symbol : variable Marshaller
location: class MarshalTester
Marshaller.marshal(sessions, writer);
^
UnmarshalTester.java:12: cannot find symbol
symbol : variable Unmarshaller
location: class UnmarshalTester
CD cd = (CD)Unmarshaller.unmarshal(CD.class, reader);
^
Note: CD.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
----------------------------------------------------

Can any one help me here ?
Thanks in Advance!


-Babu
 
reply
    Bookmark Topic Watch Topic
  • New Topic