• 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 options

 
Ranch Hand
Posts: 38
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

classpath variable is not defined for both Windows and Linux /Ubuntu/


WindowsXP

File -> c:\documents and settings\fbi\desktop\base\B1.java
current directory c:\documents and settings\fbi

java -cp Desktop\base B1 - OK
java -cp "c:\documents and settings\fbi\desktop\base" B1 - OK
java -cp c:\documents and settings\fbi\desktop\base B1 - NOT OK

javac -cp desktop\base\ B1.java - NOT OK
javac -classpath desktop\base B1.java - NOT OK
javac -cp "c:\documents and settings\fbi\desktop\base" B1.java - NOT OK
javac -classpath "c:\documents and settings\fbi\desktop\base" B1.java - NOT OK
current dir to c:\documents and settings\fbi\desktop\base\
javac B1.java - OK

Ubuntu

File -> /home/valentino/base/B1.java
current directory "home"

java -cp valentino/base B1 - OK
java -cp /home/valentino/base B1 - OK

javac -cp /home/valentino/base B1.java - NOT OK
javac -cp valentino/base B1.java - NOT OK
javac -cp /valentino/base B1.java - NOT OK
current dir to /home/valentino/base
javac B1.java - OK

So why javac seems to be not working ? What went wrong?
The B1 class is not in any package, so all i need is just to tell the javac where it is, don't I?
 
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

So why javac seems to be not working ? What went wrong?



What's the error message? We highly doubt that the command prompt just returns "NOT OK"...

Henry
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The CP must either point to the folder that contains the classes or to a JAR file. Some of your CPs are pointing to source files which will not help
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Windows XP

Your command prompt must be in where the file is located and then you can use the command:-


javac -classpath com:. -g Filename.java
The above is the right syntax to execute the java file

The -classpath which itself has an argument of com:. and -g and then passes it to the compiler and it compiles.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javac file arguments are always going to be the path relative to the current directory, even if they
are not part of a package:

file: /home/ken/java/test.java //default package
current dir: /
javac invocation: javac home/ken/java/test.java

___

file: /home/ken/java/com/test.java //package com
current dir: /
javac invocation: javac home/ken/java/com/test.java

Even when test.java is in package com, the -cp option cannot be used (as far as I know). You use -cp in conjunction with
javac when you need .class files from another package, basically.

And this is different from -cp in conjunction with java, where the -cp argument should be the directory(ies) that contain(s)
the first directory in the package.
 
Valentin Ivanov
Ranch Hand
Posts: 38
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry the output is:

javac: file not found: B1.java
Usage: javac <options> <source files>
use -help for a list of possible options


I know what that message means, but I don't know why javac can't find the file. I think i use -cp option correct, don't I?

Deepak thanks for helping me, but a think all of my CP's are pointing to "base" directory which contains the B1.java
 
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
The classpath is only used to find compiled classes, not to find source files. So setting the classpath to a directory that contains your source code will not work. You can just enter the whole path to your source file, like this:

javac C:\some\directory\MyProgram.java
 
Valentin Ivanov
Ranch Hand
Posts: 38
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote:The classpath is only used to find compiled classes, not to find source files. So setting the classpath to a directory that contains your source code will not work.


Thanks, i didn't know -cp is looking only for compiled files and not source,

You can just enter the whole path to your source file, like this:

javac C:\some\directory\MyProgram.java



i did it /I've shown above/ , but still not working
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if using the absolute path isn't working with javac, you may have a problem with your $PATH variable (Windows environmental variable).
And with the Ubuntu path variable.

Either that or you had a typo. Anyway, the concept is that javac doesn't care about packages so you need to give it an argument
that tells it where the actual .java file is, either a relative path or an absolute path. You don't use -cp with javac, I believe, unless you are
pointing to .class files used for compilation of your .java file.

I did read that if the source file for the class file you point to with -cp is found [in the same directory,] the source file may be recompiled, rather than using the .class file. see the javac man page for more info.
 
reply
    Bookmark Topic Watch Topic
  • New Topic