• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Invalid Flag Error when using javac

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..!

 
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my guess is that something doesn't like the spaces in your directory name. try enclosing it in quotes.
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic