![]() |
command-line main() classpath etc.
I have a class file with a main method in the following directory:
C:\tea\emat\web\WEB-INF\classes\emat\com\edi The name of the file is: Edi210Parser. The class has a main method. I've developed and tested the file under Eclipse, which has shielded me from the classpath and command-line args. I've defined the file in the Windows classpath setting as: C:\tea\emat\web\WEB-INF\classes\emat\com\edi; For the life of me I can't remember how to run the file from a Windows command-line. I've tried the following: c:>java -classpath emat\com\edi\Edi210Parser out.txt (to read the input file that exists in the same directory) I've changed directories to the place where the file is: C:\tea\emat\web\WEB-INF\classes\emat\com\edi and run: c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java Edi210Parser out.txt and c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java emat.com.edi.Edi210Parser out.txt The closest I've come to getting it right is: c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java -classpath EdiParser210 out.txt which results in: Exception in thread "main" java.lang.NoClassDefFoundError: out/txt, which makes no sense at this point but shows (or seems to) that the class was found. Any help would be appreciated.... |
Re: command-line main() classpath etc.
bb wrote On 01/10/06 18:00,: > I have a class file with a main method in the following directory: > C:\tea\emat\web\WEB-INF\classes\emat\com\edi > The name of the file is: Edi210Parser. The class has a main method. > I've developed and tested the file under Eclipse, which has shielded me > > from the classpath and command-line args. > > > I've defined the file in the Windows classpath setting as: > C:\tea\emat\web\WEB-INF\classes\emat\com\edi; > > > For the life of me I can't remember how to run the file from a Windows > command-line. I've tried the following: > c:>java -classpath emat\com\edi\Edi210Parser out.txt (to read the input > > file that exists in the same directory) The crucial piece of information you've omitted is the name of the class whose main() method you're trying to run. Yes, I know you said "Edi210Parser" -- but that's only the least-significant piece of the name: you've not divulged the package portion. I'm going to guess that Edi210Parser.java begins with "package com.edi;" so that the full name of the class is "com.edi.Edi210Parser" (make adjustments as necessary for whatever the actual package name is). Point #1, then, is that com.edi.Edi210Parser is the name you must supply on the java command line; Java is not a mind-reader, able to pluck the package name out of thin air. Once you've done that much, Java will look for the class by starting where the classpath ends (roughly speaking) and looking for com\edi\Edi210Parser.class. See the correspondence between the package name and the directory structure? Good. So your classpath should be set to c:\tea\emat\web\WEB-INF\classes\emat, because that's where you want the search for com\... to begin. Finally, setting the classpath and specifying the full class name doesn't change your current directory in any way. If you want "out.txt" to be found in some directory, you need to cd to that directory before you start Java. Putting it all together: cd directory-where-out.txt-lives java -classpath c:\tea\emat\web\WEB-INF\classes\emat com.edi.Edi210Parser out.txt (The final two lines are really just one, wrapped for legibility.) Adjust as needed for your actual structure -- for example, if the package is emat.com.edi, you'd set the classpath one level higher and prepend "emat." to the package name on the command line. -- Eric.Sosman@sun.com |
Re: command-line main() classpath etc.
bb wrote:
> I have a class file with a main method in the following directory: > C:\tea\emat\web\WEB-INF\classes\emat\com\edi > The name of the file is: Edi210Parser. The class has a main method. > I've developed and tested the file under Eclipse, which has shielded me > > from the classpath and command-line args. > > > I've defined the file in the Windows classpath setting as: > C:\tea\emat\web\WEB-INF\classes\emat\com\edi; > > > For the life of me I can't remember how to run the file from a Windows > command-line. I've tried the following: > c:>java -classpath emat\com\edi\Edi210Parser out.txt (to read the input > > file that exists in the same directory) > > > I've changed directories to the place where the file is: > C:\tea\emat\web\WEB-INF\classes\emat\com\edi and run: > c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java Edi210Parser out.txt > and > c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java > emat.com.edi.Edi210Parser out.txt > > > The closest I've come to getting it right is: > c:\tea\emat\web\WEB-INF\classes\emat\com\edi>java -classpath > EdiParser210 out.txt > which results in: > Exception in thread "main" java.lang.NoClassDefFoundError: out/txt, > which makes no sense at this point but shows (or seems to) that the > class was found. > > > Any help would be appreciated.... > If your main class is in package com.edi then you need to be in the directory above this, so C:\tea\emat\web\WEB-INF\classes\emat\ then run java -classpath . com.edi.EdiParser210 out.txt Though the -classpath is probably un-needed. If your package is different then adjust accordingly. James |
| All times are GMT. The time now is 10:00 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.