File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javac woes.

 
Kean Erickson
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20829
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kean Erickson
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20169
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20169
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic