• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javac woes.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I'm using the syntax proposed at the end here:
https://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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28174
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28174
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, guys.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic