Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid Flag Error when using javac

 
Rakesh Rajmohan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my guess is that something doesn't like the spaces in your directory name. try enclosing it in quotes.
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rakesh Rajmohan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try putting your jar in, say, c:\jartest and setting the classpath accordingly?
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe try this (putting quotes around the entire classpath)?

javac -classpath "%CLASSPATH%;classes;.;" -d classes src\com\example\web\BeerServlet.java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic