Results 1 to 11 of 11
Thread: Simple question
- 09-29-2012, 01:08 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
Compiling without being in java file directory
Everytime i have to compile a java file i am asked to "go into" directory where the file is at (as many of you know).
So my question is - what must i/or can i do so that the compiler locates the file without the need of going into the directory manually.
I got windows 7 32-bitLast edited by Games2Design; 09-29-2012 at 04:03 PM.
- 09-29-2012, 02:47 PM #2
Re: Simple question
Please go through the Forum Rules - particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-29-2012, 02:49 PM #3
Re: Simple question
You need to specify the absolute or relative path of the source file. You also need to ensure that any and all dependencies are available on the classpath, usually fia the -cp flag to javac..
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-29-2012, 04:05 PM #4
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
- 09-29-2012, 04:19 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Simple question
Suppose you have a directory 'a' under the root; also suppose that directory /a has two subdirectories 'b' and 'c'; so they are /a/b and /a/c. Now suppose your current working directory is /a/b (i.e. you're 'in' that directory) and your source file YourFile.java is stored in directory /a/c. There are a couple of ways to compile that file:
using a relative path: javac ../c/YourFile.java
using an absolute path: javac /a/c/YourFile.java
(use backslashes '\' if you're on a MS Windows machine).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-30-2012, 06:45 PM #6
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
Re: Simple question
I checked Youtube videos for help to set CLASSPATH. And i have java programs in a folder at C drive called "Java programs".
So i made CLASSPATH as a user and system variable, with directory adress to the folder.
But still, i can't just compile without having to write path or go into directories through CMD.
I don't get why it's not working?
CLASSPATH : Is a path that helps javac find the classes right? So why is it not working?
-
Re: Simple question
We may need to see your attempts, your command window dumps and get a knowledge of the package structure of your class to help more.
- 09-30-2012, 07:13 PM #8
Re: Simple question
Don't set the system variables, use the -cp or -classpath flag on the javac / java /javaw command line. Also and probably more importantly, the classpath, whether read for a system variable, a command line, or a jar manifest, is where the java executables look for dependencies. When compiling a .java source file, you have to pass the path to the source file to javac exactly as JosAH explained.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-30-2012, 07:24 PM #9
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
-
Re: Simple question
I agree with Darryl -- you don't want to set the system classpath but rather want to set it on the command line when you make your javac and java calls using the -cp command.
Sometimes all you have to do is pass in a period for *this* directory: -cp .
- 09-30-2012, 07:54 PM #11
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
Similar Threads
-
simple question
By jwl in forum New To JavaReplies: 4Last Post: 08-05-2012, 02:31 AM -
A simple question
By chris.bos in forum New To JavaReplies: 11Last Post: 12-02-2011, 05:37 PM -
Please help. Simple question
By owencain in forum New To JavaReplies: 14Last Post: 06-16-2011, 01:07 AM -
Simple question
By Qsc in forum New To JavaReplies: 6Last Post: 03-06-2011, 11:24 PM -
Probably a really simple question...
By ibanez270dx in forum New To JavaReplies: 0Last Post: 11-16-2007, 01:27 AM


LinkBack URL
About LinkBacks
Reply With Quote



Bookmarks