File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Invalid Flag Error when using javac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Invalid Flag Error when using javac" Watch "Invalid Flag Error when using javac" New topic
Author

Invalid Flag Error when using javac

Rakesh Rajmohan
Greenhorn

Joined: Jul 09, 2009
Posts: 22
Hello.. I am trying to compile a servlet using "javac -classpath C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java" from the folder where src\com... is available..

But I get an error as below..

javac: invalid flag: Files\Apache
Usage: javac <options> <source files>
use -help for a list of possible options

Seeking your help around this.. Thanks..!

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11229
    
  16

my guess is that something doesn't like the spaces in your directory name. try enclosing it in quotes.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

fred rosenberger wrote:my guess is that something doesn't like the spaces in your directory name. try enclosing it in quotes.

Yes, that's exactly why. Also, if using Windows, you must use a semicolon to separate paths in your classpath, not a colon.


SCJP 6 || SCWCD 5
Rakesh Rajmohan
Greenhorn

Joined: Jul 09, 2009
Posts: 22
I Tried doing it this way, but in vain...

javac -classpath %CLASSPATH%;classes;.; -d classes src\com\example\web\BeerServlet.java

wherein my classpath has --> %TOMCAT_HOME%\common\lib\servlet-api.jar; and
TOMCAT_HOME is C:\Program Files\Apache Software Foundation\Tomcat 5.5..

Both set in environment variable..

Even now I get the same error..!
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Rakesh Rajmohan wrote:I Tried doing it this way, but in vain...

javac -classpath %CLASSPATH%;classes;.; -d classes src\com\example\web\BeerServlet.java

wherein my classpath has --> %TOMCAT_HOME%\common\lib\servlet-api.jar; and
TOMCAT_HOME is C:\Program Files\Apache Software Foundation\Tomcat 5.5..

Both set in environment variable..

Even now I get the same error..!


There's still some spaces inside the path in the TOMCAT_HOME variable. Reset the variable, this time surrounding the path with double quotes.
"C:\Program Files\Apache Software Foundation\Tomcat 5.5"
Rakesh Rajmohan
Greenhorn

Joined: Jul 09, 2009
Posts: 22
Hello.. As I said my TOMCAT_HOME is an environment variable so I can give only this "C:\Program Files\Apache Software Foundation\Tomcat 5.5"

And The CLASSPATH Environment variable I have set is "%TOMCAT_HOME%\common\lib\servlet-api.jar;"

So there's no question of extra whitespaces (I have checked) it... The path I have in my CLASSPATH variable is the exact path to the servlet-api.jar

And I cd to the directory where "src\com\example\web\BeerServlet.java" is present and execute it as below for the below said error.

javac -classpath %CLASSPATH%;classes;.; -d classes src\com\example\web\BeerServlet.java

Please help. Thanks!

Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
did you try putting your jar in, say, c:\jartest and setting the classpath accordingly?
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Maybe try this (putting quotes around the entire classpath)?

javac -classpath "%CLASSPATH%;classes;.;" -d classes src\com\example\web\BeerServlet.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid Flag Error when using javac