Results 1 to 5 of 5
- 11-16-2010, 09:16 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 67
- Rep Power
- 0
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:
Here is the code: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>
Can someone tell me whats wrong? ThanksJava 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()); } }
- 11-16-2010, 09:34 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
"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? :)
-
- 11-17-2010, 06:45 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 67
- Rep Power
- 0
- 11-17-2010, 06:58 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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
-
Problem while redirecting script output to a file using java
By umapathy_sekar in forum Advanced JavaReplies: 4Last Post: 11-09-2010, 09:33 AM -
Does anyone know how to read a log file in .log and output the data using java langua
By motress in forum EclipseReplies: 1Last Post: 02-04-2010, 09:17 PM -
java question output file
By dazednconfused in forum New To JavaReplies: 3Last Post: 09-17-2009, 03:07 PM -
Redirecting output at Thread level
By beezerbutt in forum Advanced JavaReplies: 8Last Post: 02-14-2009, 11:19 PM -
the explanation of output of simple java program
By amol84 in forum New To JavaReplies: 1Last Post: 11-06-2008, 05:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks