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 javac woes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javac woes." Watch "javac woes." New topic
Author

javac woes.

Kean Erickson
Greenhorn

Joined: Aug 04, 2010
Posts: 11
I'm trying to compile a .java file in linux. I've read the syntax over and over again, but javac denies me still.
javac -classpath blahblah/ ThisNeedsClasses.java

..with blahblah containing a bunch of class files.emphasis on the space between the dir and java file. javac still seems to be completely ignoring the classpath param--it spits out the same errors regardless of what I put for classpath.

Javac is unbelievably cumbersome. Why can't it compile a bunch of java files recursively in different directories without my having to specify every subdirectory? What year are we in?
Kean Erickson
Greenhorn

Joined: Aug 04, 2010
Posts: 11
Now I'm using the syntax proposed at the end here:
http://www.coderanch.com/forums/posts/quote/0/2172824

"javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:.classes src/com/example/model/BeerExpert.java"

I have no idea what the colon is doing in the middle of the above string. I'm using absolute addresses for the .jar and .java file and javac still ignores everything in the .jar.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19060
    
  40

Kean Erickson wrote:
I have no idea what the colon is doing in the middle of the above string.


The colon is a classpath separator -- assuming that you are using unix. If you are using windows, then the classpath separator should be a semi-colon.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Kean Erickson wrote:"javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:.classes src/com/example/model/BeerExpert.java"


You are still missing part of what is described in the post you reference:
The original poster said this:

David corrects the original poster saying it shouldn't be "dot space classes" and should be "dot forward-slash classes:

This is assuming the compiled results are in the "classes" subdirectory of the current directory.


Steve
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

Kean Erickson wrote:Javac is unbelievably cumbersome. Why can't it compile a bunch of java files recursively in different directories without my having to specify every subdirectory? What year are we in?

In "real" projects, people don't compile lots of Java source files by hand, by typing in javac commands. An IDE such as NetBeans or Eclipse can manage all of that for you, or tools such as Apache Ant or Maven.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Kean Erickson
Greenhorn

Joined: Aug 04, 2010
Posts: 11
Using Windows:

C:\compile>javac -classpath ./lol.jar;./TransactionFactory.java
javac: no source files


The jar and java file are in the same directory. What's wrong here?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You haven't specified anything to compile. And by the way, putting .java files in the classpath is pointless.

Or did you mean that lol.jar and the current directory should be the classpath, and TransactionFactory.java is the source you want to compile? If that's what you meant, you do have to leave space between the classpath and the name of the source you want to compile. Like so:



(Note that I simplified your classpath a bit: "lol.jar" means "lol.jar (by default in the current working directory)" and "./lol.jar" means "look in the current working directory and get lol.jar". In other words the two expressions are equivalent.)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

Paul Clapham wrote:(Note that I simplified your classpath a bit: "lol.jar" means "lol.jar (by default in the current working directory)" and "./lol.jar" means "look in the current working directory and get lol.jar". In other words the two expressions are equivalent.)

No, Windows uses backslashes, not forward slashes, to separate directory names and file names. You could have written: .\lol.jar but there's no need to add the [tt].\[\tt].

Windows: Backslashes \ to separate directory names and file names and semi-colons ; to separate path elements.

Linux, Mac OS X: Forward slashes / to separate directory names and file names and colons : to separate path elements.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Jesper de Jong wrote:
Paul Clapham wrote:(Note that I simplified your classpath a bit: "lol.jar" means "lol.jar (by default in the current working directory)" and "./lol.jar" means "look in the current working directory and get lol.jar". In other words the two expressions are equivalent.)

No, Windows uses backslashes, not forward slashes, to separate directory names and file names. You could have written: .\lol.jar but there's no need to add the [tt].\[\tt].


That's true, but in practice almost every program which runs in the Windows command line will accept both / and \ as path separators. I have no idea whether javac does, though.
Kean Erickson
Greenhorn

Joined: Aug 04, 2010
Posts: 11
Thanks, guys.
 
 
subject: javac woes.