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 n00b issues compiling from the Windows command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "n00b issues compiling from the Windows command line" Watch "n00b issues compiling from the Windows command line" New topic
Author

n00b issues compiling from the Windows command line

Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
hi everybody, as you can see I'm a newbie here I introduce myself : I'm 22, I'm from Italy and I study at the Politecnico di Torino.
I got to know The Big Moose Salon as I purchased a book from the "Head First" series, actually the one about JSP and servlets, I hope I can find a good place here to learn and to help other people.
I've got already experience in OO programming and GUI development, but our teachers discourage us to work without IDEs and I now figured out that I know nothing at all about compiling .java files.
now I'm following the very first tutorial in the book about a small servlet which creates a dynamic page with the current date.
Long story short, I'jm a windows XP user and I've got some problems when it comes to execute javac command from the shell. I type in the command:

and all I get back is

and then all the possible options.

i'm working with tomcat 7.0, and all the environment variables seem to be ok.
I hope somebody can find where I'm wrong 'cause I'm going nuts


[I study here]
Regards, Fiò
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61102
    
  66

Welcome to the Ranch.

This doesn't really have much to do with Tomcat (except for grabbing the jar files from it), but more with compiling from the command line.

I'll move this to a more appropriate location with a corresponding change of title for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
thank you . I also realized that somehow ( ) I posted clumsily the same topic two times.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18764
    
  40

Fiorenza Oppici wrote: I posted clumsily the same topic two times.


Your other copy of this topic has been deleted.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18764
    
  40

Fiorenza Oppici wrote:

and all I get back is



The "-d" option is to specify a destination directory. And it looks like you are trying to use the name of the source file as the destination directory.

Did you accidentally typed an underscore, instead of a space?

Henry
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

ummm... I am not an expert on such things...but what I see is this:

you use the -classpath option to tell the compiler where to find .class files
you use the -d option to tell it where to put the compiled files

but you don't ever say what the .java file is you want to compile.


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

Joined: Jul 22, 2010
Posts: 38
Henry Wong wrote:
Fiorenza Oppici wrote:

and all I get back is



The "-d" option is to specify a destination directory. And it looks like you are trying to use the name of the source file as the destination directory.

Did you accidentally typed an underscore, instead of a space?

Henry

yes. I don't know why i typed wrong, now it compiles correctly.

now I ("just") have to figure out where I've to install libraries or stuff, as it can't recognise javax.servlet.* and the other packages i imported in the class.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61102
    
  66

Fiorenza Oppici wrote:
now I ("just") have to figure out where I've to install libraries or stuff, as it can't recognise javax.servlet.* and the other packages i imported in the class.

You should not have to install anything. If you correctly include the jar files in your classpath, all will be well. Bear in mind the Windows command line is very finicky... especially about spaces in file and folder names.
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
Bear Bibeault wrote:
Fiorenza Oppici wrote:
now I ("just") have to figure out where I've to install libraries or stuff, as it can't recognise javax.servlet.* and the other packages i imported in the class.

You should not have to install anything. If you correctly include the jar files in your classpath, all will be well. Bear in mind the Windows command line is very finicky... especially about spaces in file and folder names.

i noticed. although I believe it could be about the bit "/common/.
I explain: on the book the command line was



but i noticed that in my tomcat directory there's no such folder as "common" so, i typed


am I wrong?


I noticed also that in the examples given in the book path slashes are forward instead of backwards and typing is


instead of javac.

I'm just a bit confused right now, sorry if I'm wasting time.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61102
    
  66

The layout of Tomcat can change from version to version. The book was written against an earlier version of Tomcat that had the common folder.

Backward slashes are a Windows-only thing.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61102
    
  66

Fiorenza Oppici wrote:sorry if I'm wasting time.

No worries. This forum is here to help you!
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
here I am again.
as you told, problem should be in underscores. i added them, as when I type in the line command from my servlet directory:



i get an error message which warns me that "Software" is parsed as a flag and not as a part of the path:



what could I do instead?

thanks for your help.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You have to use double quotations if your directories include a space :
javac -classpath "c:\Programmi\Apache Software Foundation\Tomcat 7.0\servlet-api.jar" -d classes src\Ch1Servlet.java


[My Blog]
All roads lead to JavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

You have spaces in the classpath. The Windows command prompt will now think you are typing separate arguments to the javac command: first "-classpath", then "c:\Programmi\Apache", then "Software", then "Foundation\Tomcat", then "7.0\servlet-api.jar". That's obviously not what you want. Put the whole path in quotes:



Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
allright! : )
it finds correctly the .jar path, thank you!

but it's not over: I think I've still got a problem with different package versions

src\Ch1Servlet.java:6: cannot access javax.servlet.http.HttpServlet
bad class file: C:\Programmi\Apache Software Foundation\Tomcat 7.0\lib\servlet-a
pi.jar(javax/servlet/http/HttpServlet.class)
class file has wrong version 50.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public class Ch1Servlet extends HttpServlet{
^
1 error

it means that the.jar file is somehow obsolete?

in my Ch1Servlet class I imported



how can the compiler recognize the package version in java class??
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Which version of java are you using ? Type "javac -version". Tomcat 7.0 requires Java SE 6 or later. (are you sure you want to use Tomcat 7 which is still in Beta ?)
Garik Ustinov
Ranch Hand

Joined: Jun 22, 2009
Posts: 31
Fiorenza Oppici wrote:
how can the compiler recognize the package version in java class??


For the compiler it's not a problem at all. You might be interested in this


SCJP, SCWCD
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
I'm using Jdk1.5.0_19, so now I downgraded to Tomcat 6.x and everything is ok.

thank you so much for your support. : )

I've still a curiosity: the -classpath options is normally used for retrieving libraries?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It's used to tell the compiler where the class files, or JAR files are. It uses the environment variable called CLASSPATH to do it, but you can override this setting using the -classpath or -cp flag.
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
Garik Ustinov wrote:
Fiorenza Oppici wrote:
how can the compiler recognize the package version in java class??


For the compiler it's not a problem at all. You might be interested in this


thank you, it's exactly the same problem i ran in.
Fiorenza Oppici
Ranch Hand

Joined: Jul 22, 2010
Posts: 38
Christophe Verré wrote:It's used to tell the compiler where the class files, or JAR files are. It uses the environment variable called CLASSPATH to do it, but you can override this setting using the -classpath or -cp flag.

thank you. I consider my question resolved now, despite I still have a lot to learn in compling without an IDE.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: n00b issues compiling from the Windows command line