Results 1 to 5 of 5
  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default Redirecting output of java program to file

    Hey there.
    I am following a tutorial on XML with java.
    It says to run the program from command prompt with the following command:

    java RssStarter > feed.rss


    But I get the following error:
    Java Code:
    D:\Users\test\Desktop\JAVA STUFF\Eclipse_workspace\RssStarter\bin>java RssS
    r > feed.rss
    Exception in thread "main" java.lang.NoClassDefFoundError: RssStarter
    Caused by: java.lang.ClassNotFoundException: RssStarter
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: RssStarter.  Program will exit.
    
    D:\Users\test\Desktop\JAVA STUFF\Eclipse_workspace\RssStarter\bin>
    Here is the code:
    Java Code:
    import nu.xom.*;
    
    public class RssStarter {
        public static void main(String[] arguments) {
            // create an <rss> element to serve as the document's root
            Element rss = new Element("rss");
            
            // add a version attribute to the element
            Attribute version = new Attribute("version", "2.0");
            rss.addAttribute(version);
            // create a <channel> element and make it a child of <rss>
            Element channel = new Element("channel");
            rss.appendChild(channel);
            // create the channel's <title>
            Element title = new Element("title");
            Text titleText = new Text("Workbench");
            title.appendChild(titleText);
            channel.appendChild(title);
            // create the channel's <link>
            Element link = new Element("link");
            Text linkText = new Text("http://www.cadenhead.org/workbench/");
            link.appendChild(linkText);
            channel.appendChild(link);
            
            // create a new document with <rss> as the root element
            Document doc = new Document(rss);
            
            // Display the XML document
            System.out.println(doc.toXML());
        }
    }
    Can someone tell me whats wrong? Thanks

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    "Eclipse_workspace"

    my question is: why you dont use then eclipse to run your code? you can define program arguments in elclipse too : Run --> Run Configurations... --> in the arguments tab.

    I dont know the XML libraray nu.xom, but in your program, you dont use the arguments array ? ;/

    doc.toXML() is only created a string containing the xml or? so you have to write it in a file by yourself?!

    can you give us the link to the tutorial?

    to your problem: do you have compiled the class? :)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    "Eclipse_workspace"

    my question is: why you dont use then eclipse to run your code? you can define program arguments in elclipse too : Run --> Run Configurations... --> in the arguments tab.

    I dont know the XML libraray nu.xom, but in your program, you dont use the arguments array ? ;/

    doc.toXML() is only created a string containing the xml or? so you have to write it in a file by yourself?!

    can you give us the link to the tutorial?

    to your problem: do you have compiled the class? :)
    I've uploaded the bit of the tutorial.

    Yep I was running the compiled class thanks
    Attached Files Attached Files

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Make sure RssStarter.class really is in the directory where you are executing java.exe. (Sorry for mentioning this, but its the place to start.)

    Then make sure that the classpath being used includes this directory. Something like:

    Java Code:
    > java -cp .;<path_to_directory_containing_nu> RssStarter

    I've put path_to_..., but it might be a jar file that contains the nu.xom classes. The point is they have to found by java.exe and using a "bare" java command will leave you at the mercy of OS variable settings.

Similar Threads

  1. Problem while redirecting script output to a file using java
    By umapathy_sekar in forum Advanced Java
    Replies: 4
    Last Post: 11-09-2010, 09:33 AM
  2. Replies: 1
    Last Post: 02-04-2010, 09:17 PM
  3. java question output file
    By dazednconfused in forum New To Java
    Replies: 3
    Last Post: 09-17-2009, 03:07 PM
  4. Redirecting output at Thread level
    By beezerbutt in forum Advanced Java
    Replies: 8
    Last Post: 02-14-2009, 11:19 PM
  5. the explanation of output of simple java program
    By amol84 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •