-
Re: How to referenc a class file. using only notepad and run cmd.
Which of the steps I asked you to do in post#20 were skipped or done differently than I suggested? For example I did not say to execute the Bootclasspath program. What else did you do?
Restore the files and folders to the way they were before post #20 and re-do the steps in post#20.
-
Re: How to referenc a class file. using only notepad and run cmd.
Quote:
Edit the FixChap5.java and add import Bootclasspath.*; to it
compile and execute it. (the default classpath should be the folder with these three things in it: the FixChap5 files and the package1 folder.)
Sorry Norm did that, what by the way is the third thing, you only mention the first two.
Cheers.
SpaceMonkey, off to work now.
-
Re: How to referenc a class file. using only notepad and run cmd.
The three things in the test folder:
FixChap5.java
FixChap5.class
package1 folder
The package1 folder should have:
Bootclasspath.java
Bootclasspath.class
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
I have the FixChap5 class and java in the folder that holds the package1 folder.
I have the Bootclasspath.java and class in the package 1 folder.
This is still not compiling, and I do not see how it will because FixChap5 and Bootclasspath both need to be in the same base folder for this to work without a class path.
Or possibly you are thinking that we need to put a:
Where as we need a:
Which works.
So if that is the case, next step.
Thanks again.
Space "Enjoying the sun on this sunny Saturday" Monkey
-
Re: How to referenc a class file. using only notepad and run cmd.
I assume the code compiles and executes now. It using the current directory (.) as the classpath.
We'll change the exercise so you need an explict -classpath value to find the class file in the package1 package.
Create a new folder: PathToPackage1 in the folder with the FixChap5 files.
Move the package1 folder and its contents to that folder.
You won't have to recompile the contents of the package1 folder.
Change to the folder containing the FixChap5 files.
Add a -classpath PathToPackage1 option to the javac command and compile the FixChap5 program.
Add the same to the java command to execute the program.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
Not sure what you mean by:
Quote:
Add a -classpath PathToPackage1 option to the javac command.
Do I type this in the Notepad where I typed the code or do I type this in the Command Prompt area, or the Environmental Variables area?
Quote:
Add the same to the java command to execute the program.
Because I do not understand the first bit I am not sure where I am supposed to add the java command, and to be honest I think the java command is the -classpath PathToPackage1, but I am not sure.
Thanks.
Space Monkey
-
Re: How to referenc a class file. using only notepad and run cmd.
The javac and java commands are entered in a command prompt on commandlines. You add options to a command by putting them on the command line folowing the name of the command.
For example:
java -cp PathToPackage1 FixChap5
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
OK will try the above, this will not remove any other classpaths to, say the bootstrap classes?
Also I like the place where you enter the environmental variables. So at some point later I would like to know how to enter the class path there.
ACTUAL RESPONSE TO YOUR INSTRUCTIONS.
I typed in
java -cp PathToPackage1 FixChap5
and got the error.
Could not find or load main class FixChap5.
Cheers.
SpaceMonkey
-
Re: How to referenc a class file. using only notepad and run cmd.
Looked online, found
java -cp . PathToPackage1 FixChap5 (The apostrophe is added.)
and that gave me the error:
Could not find or load main class PathToPackage1.
-
Re: How to referenc a class file. using only notepad and run cmd.
Yes, I left out the pointer to the current directory (.)
Separate the two paths with a ; not a space:
java -cp .;PathToPackage1 FixChap5
Here the classpath points to the current folder where the FixChap5 class is located
and to the PathToPackage1 folder where the package1 folder is.
package1.Bootclasspath is a class referenced by FixChap5
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
"-cp" is that short for "Current Path"?
It works when I type that in, but how do I set the class path and not have to type that in, can I set it in the "Environmental Variables" ?
Also lots of thanks, wanted to get my question in first. lol.
Well it works. Thanks again.
Also it the "." indicative of "this folder" or something like that?
Space Monkey.
-
Re: How to referenc a class file. using only notepad and run cmd.
-cp short for -classpath
You won't want to set the ENVIRONMENT variable for every set of programs you write. Use the -cp option on the javac and java commands. Make a batch file with the commandline
To execute the Bootclasspath program from the folder containing the PathToPackage1 folder:
java -cp PathToPackage1 package1.Bootclasspath
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
Sorry I was not clear,
I want to know how to run the program FixChap5 without typing the the classpath. I want to set the class path some where so I do not have to type in:
-cp .;PathToPackage1 FixChap5
So ideal solutions would be:
java FixChap5
So that would entail setting the classpath for FixChap5 to find the class Bootclasspath automatically.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
Y
Quote:
ou won't want to set the ENVIRONMENT variable for every set of programs you write.
Why ?
Now I do because I want to practice it so I do not forget it.
Also is the notation different?
My main problem with all of this was I did not know that I needed to put "java" before the -cp.
I would never have worked that out.
-
Re: How to referenc a class file. using only notepad and run cmd.
Use a batch file with the full commandline to save entering the full classpath and other commandline options.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
When you say use a batch file. Do you mean in the batch file properties, or in the code in the FixChap5 or in the Bootclasspath, and if so what is the notation?
Cheers.
SM.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
We do not enter FixChap5 anywhere. How can the compute know that that is the program we want to run?
-
Re: How to referenc a class file. using only notepad and run cmd.
On windows a batch file's extension is .bat. I use them for executing test programs. You enter the name of the batchfile and windows reads it and executes it contents.
Here's a sample:
Quote:
@Rem Setup for access to My HTTP Server - Run in a DOS prompt window
@ECHO OFF
%DEV_DRIVE%
CD %DEV_HOME%\JavaDevelopment\
Echo - - - - - - - - - -
Echo Starting HTTP server - This window can be closed when 'Finished'
Echo Remember to append :8080 to URL to reach this server!
Java.exe -DDEV_DRIVE=%DEV_DRIVE% -DDEV_HOME=%DEV_HOME% -DDOCS_HOME=%DOCS_HOME% -cp %DEV_HOME%\Java\jsdk2.0\lib\jsdk.jar;%DEV_HOME%\Ja vaDevelopment\HTTPServer\;. HTTPServer.HTTPServerMain -p 8088 %1 %2 %3 %4 %5 %6
MORE
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
Waaaaaa. What is that crazyness you printing in your quote up there. lol
Where exactly do you enter this information. I am never sure if this is in the command line or in the program file.
PLEASE ANSWER THIS QUESTION.
How did the computer know we where working on FixChap5 file?
Because the line java -cp .;PathToPackage package1.*;
has not got Fix Chap5 in there anywhere.
Thanks again
-
Re: How to referenc a class file. using only notepad and run cmd.
Create a batchfile that contains the full commandline you use to execute the java program.
Quote:
java -cp .;PathToPackage package1.*;
Where did that line come from? That is not a valid commandline.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
So correct is; java -cp .;PathToPackage1 FixChap5 and thus the FixChap5 is at the end.
If the FixChap5 class is not in the package "PathToPackage1" how can it call the Bootstrapclass method if the commandline telling it to call the method is written in a file already in the PathToPackage1 package. ?
Are you saying to write a bit of code that prints out:
java -cp .;PathToPackage1 FixChap5
onto the command Prompt area that then builds the bridge between the two bits of code?
Cheers.
Space Monkey
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
java -cp .;PathToPackage1 package1.Bootclasspath
The above bit of code has not FixChap5 in there anywhere, can you explain how it knows that FixChap5 is the calling program?
Cheers.
Space Monkey.
-
Re: How to referenc a class file. using only notepad and run cmd.
Quote:
java -cp .;PathToPackage1 package1.Bootclasspath
The FixChap5 is not involved at all in the above.
Look at the Bootclasspath program. It has a main() method that is being called by the java program.
Quote:
FixChap5 class is not in the package "PathToPackage1"
There is no package named: PathToPackage1
FixChap5 is not in any package.
PathToPackage1 is the path from the current directory to the package1 directory.
Bootclasspath is in the package1 package. That classpath value is how the java program finds the package1 package.
Create a file named: FixChap5.bat in the folder with the FixChap5 files and put the following lines into it:
java -cp .;PathToPackage1 FixChap5
MORE
Then double click on the file.
-
Re: How to referenc a class file. using only notepad and run cmd.
Dear Norm:
NICE
What witchcraft is this!!!!.
OK now that is what I was talking about this I can play around with.
I am going to look up bat files and the rest of this.
You have given me a good jumping off point, thanks.
I will be back tomorrow, with results and questions.
Many thanks.
Space Monkey.
P.S. I will mark this as answered sometime after tomorrow after I have come back with some interesting questions, of which I will have many.
-
Re: How to referenc a class file. using only notepad and run cmd.
I use frequently use batch files. Knowing how to write them will be useful for you.