File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Marshaller Example with Castor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Marshaller Example with Castor" Watch "Marshaller Example with Castor" New topic

Marshaller Example with Castor

babu cap

Joined: Dec 02, 2010
Posts: 1
I tried to execute sample program using castor( tried with version and 1.3.x)

My Java Stuff:
import java.util.ArrayList;
import java.util.List;

/** A class to represent CDs */
public class CD implements {

/** 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() {

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

public void setName(String 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();

2. MarshalTester

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) {

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

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

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

Can any one help me here ?
Thanks in Advance!

I agree. Here's the link:
subject: Marshaller Example with Castor
It's not a secret anymore!