Running programs in Textpad
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Running programs in Textpad
i am getting a java.class.NoClassDefFoundError everytime i try to run an application. It compiles find. What is the problem?
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
Textpad and Class Paths Explained
Textpad and Class Paths Explained
First lets get an understanding of the java tools (javac and java)
that textpad uses and how these applications behave by themselves.
Both these tools will use the current directory as the default class
directory if no classpath is specified.
javac tool alone
This means that if I have my program called "AreaTest.java" in "c:\myprog", javac expects to find
all source code in the folder "myprog" which is located on drive c and any
packages that are called in the program (if any) as subfolders to the "myprog" folder.
This means that to compile the program from a DOS window with the directory set to
"c:\myprog" I would type: "javac AreaTest.java".
If the program uses a ParsedString class that I have defined in the package of "rogerslib", with source
code in AreaTest.java such as "import rogerslib.ParsedString;", then javac will look for the "rogerslib"
folder as a subfolder of myProg folder. Remember that packages are subfolders of the root class path.
Therefore, javac would compile successfully from the DOS window set to the directory of "c:\myprog" if
I had the class file for ParsedString in the folder of "C:\myprog\rogerslib".
It is also important to note here that the java tools are very particular regarding path name syntax.
While Windows will let you name your folders with spaces and periods, java tools path name parser may
have a problem interpreting them. All folders should be formed without spaces and special characters.
Now lets assume we want our library located someplace other than a subfolder of "myprog". Lets put the
package of "rogerslib" in a sparate folder on c-drive called "javalib" (c:\javalib\rogerslib). Since
some of our class files are no longer located in the default directory, we need to specify a class path
that includes where all the rest of our classes can be found. In this case we would run javac
from a DOS window set to "c:myprog" by typing:
javac -classpath c:\javalib ParseWordTest.java
javac is looking for the package(folder) rogerslib, and this tells it to look for it in "c:\javalib".
Note that packages are always subfolders to the final folder of class path, while individual classes
would be in the final folder of class path itself. If your program needed a class file that was not
part of a package, it would expect to find it in "c:\javalib" in this case.
javac tool with textpad
From this foundation we can better understand what textpad is doing with its settings and, more
importantly, how to adjust them to our needs.
If we compile the file from within textpad, we will need to make some adjustments from the default
settings of each tool we use if we change the classpath settings. We will first look at the settings
for javac in textpad. You can check them by choosing "configure" from the menu at the top of textpad
and then choosing "preferences". From here you should click on the "+" next to "tools" on the left
side of the window. You will see options "Compile Java" and "Run Java Application". Click on
"Compile Java" and you will see a window open that allows you to change the parameters.
You will see that default parameter set to "$File". This, is defined in the help document of textpad
as "The fully qualified filename of the current document". This means it is the name and the file path.
If I have "AreaTest.java" loaded into textpad and displayed on the screen, and I choose "Compile Java"
from the "Tools" option, it is the equivalent of running javac with the file name and full path
extention (javac c:\myprog\AreaTest.java). As long as all required class files are in myprog and my
packages (if any) are named as subfolders of "myprog", this will compile correctly and we don't need to
change the default of "$File".
Now lets assume, as we did in our second example in using bare javac, that we have moved our package,
"rogerslib" to the folder "javalib" in the "c:\" root directory. In this case we need to run javac
with the class path parameter "-classpath c:\javalib" and specify the source file "AreaTest.java".
Remember, in bare javac this was done with the complete command line
"javac -classpath c:\javalib AreaTest.java". Also note that we could get away with not feeding the
whole file path of "AreaTest" because our Dos window was already set to that directory.
In textpad, with "$File" representing our sourcecode file (AreaTest.java) including the full path, we
now add the class path option to this parameter to javac by setting the parameter from "$File" to
"-classpath c:\javalib $File".
This translates to the command line statement of "javac -classpath c:\javalib c:\myprog\AreaTest.java",
which is exactly what we want.
java tool alone
Bare java expects to find all the necessary class files in the current directory, so we could run
"AreaTest" from a dos window set the "c:\myprog" by typing "java AreaTest". This causes java to seek
the program "AreaTest.class" from the current directory. If, however, we placed our package file in
another directory as in our first example (rogerslib placed in javalib folder in c:\), we would have
to set the class path. Here we would type:
"java -classpath c:\javalib;c:\myprog AreaTest".
Look at this line carefully so you understand what is actually taking place. Once we start telling
java tool where our classes are, we must specifically tell it where ALL of the class files can be
found. If we just told it that classpath was "c:\javalib", and then told it to run "AreaTest", it
would assume that "AreaTest.class" was also located in "javalib" and this is not true. This is why the
line "java -classpath c:\javalib AreaTest" will return error. We must fully declare all class paths,
which includes the location of the main program class, "AreaTest", which is still in "myprog". We do
this by giving the classpath option multiple arguments (in this case two of them). This is done by the
segment of the command line "-classpath c:\javalib;c:\myprog". Here we are giving two class paths
separated by the ";" character as described in java documentation.
java tool with textpad
Now that we understand bare java, we are ready to run it in textpad. Just as no changes were
required from the default setting in textpad for compiling with all class files in the default
directories, there is no need to alter textpad's default for running the application. Go to
textpad's "run application" parameter settings just as you found the javac parameter
(Configure -> Preferences) click on the "+" by "tools", but this time select "Run Java Application".
For the default parameter for the "java" tool you see "$BaseName". This is defined by the help doc as
"$FileName, stripped of any extension". This would therefore be the equivalent command line of
"java AreaTest". Since all class files are in the current directory this would run fine.
Now lets use our example again where we move class files out of their current directory. Again we
will seek out the package "rogerslib" in the directory "javalib". We know from our discussion of bare
java that java is seeking the class path and the file name of the main program class as parameters.
Therefore we will set our parameter from the default of "$BaseName" to:
-classpath c:\javalib;$FileDir $BaseName
Here we use "$FileDir" which is defined in the help doc as
"The drive and directory of the current document". Assuming we have "AreaTest.java" loaded in textpad,
when we now choose "run java application" from the tools menu, this parameter setting is the equivalent
of "java -classpath c:\javalib;c:\myprog AreaTest". This will work fine and is precisely what we want,
as it conforms to the successful command line we used in our 'bare java' example just before.
Hopefully this will clear up some of the confusion regarding class path settings using the tools by
themselves and within textpad.
John Rogers
jrogers@pclink.com
First lets get an understanding of the java tools (javac and java)
that textpad uses and how these applications behave by themselves.
Both these tools will use the current directory as the default class
directory if no classpath is specified.
javac tool alone
This means that if I have my program called "AreaTest.java" in "c:\myprog", javac expects to find
all source code in the folder "myprog" which is located on drive c and any
packages that are called in the program (if any) as subfolders to the "myprog" folder.
This means that to compile the program from a DOS window with the directory set to
"c:\myprog" I would type: "javac AreaTest.java".
If the program uses a ParsedString class that I have defined in the package of "rogerslib", with source
code in AreaTest.java such as "import rogerslib.ParsedString;", then javac will look for the "rogerslib"
folder as a subfolder of myProg folder. Remember that packages are subfolders of the root class path.
Therefore, javac would compile successfully from the DOS window set to the directory of "c:\myprog" if
I had the class file for ParsedString in the folder of "C:\myprog\rogerslib".
It is also important to note here that the java tools are very particular regarding path name syntax.
While Windows will let you name your folders with spaces and periods, java tools path name parser may
have a problem interpreting them. All folders should be formed without spaces and special characters.
Now lets assume we want our library located someplace other than a subfolder of "myprog". Lets put the
package of "rogerslib" in a sparate folder on c-drive called "javalib" (c:\javalib\rogerslib). Since
some of our class files are no longer located in the default directory, we need to specify a class path
that includes where all the rest of our classes can be found. In this case we would run javac
from a DOS window set to "c:myprog" by typing:
javac -classpath c:\javalib ParseWordTest.java
javac is looking for the package(folder) rogerslib, and this tells it to look for it in "c:\javalib".
Note that packages are always subfolders to the final folder of class path, while individual classes
would be in the final folder of class path itself. If your program needed a class file that was not
part of a package, it would expect to find it in "c:\javalib" in this case.
javac tool with textpad
From this foundation we can better understand what textpad is doing with its settings and, more
importantly, how to adjust them to our needs.
If we compile the file from within textpad, we will need to make some adjustments from the default
settings of each tool we use if we change the classpath settings. We will first look at the settings
for javac in textpad. You can check them by choosing "configure" from the menu at the top of textpad
and then choosing "preferences". From here you should click on the "+" next to "tools" on the left
side of the window. You will see options "Compile Java" and "Run Java Application". Click on
"Compile Java" and you will see a window open that allows you to change the parameters.
You will see that default parameter set to "$File". This, is defined in the help document of textpad
as "The fully qualified filename of the current document". This means it is the name and the file path.
If I have "AreaTest.java" loaded into textpad and displayed on the screen, and I choose "Compile Java"
from the "Tools" option, it is the equivalent of running javac with the file name and full path
extention (javac c:\myprog\AreaTest.java). As long as all required class files are in myprog and my
packages (if any) are named as subfolders of "myprog", this will compile correctly and we don't need to
change the default of "$File".
Now lets assume, as we did in our second example in using bare javac, that we have moved our package,
"rogerslib" to the folder "javalib" in the "c:\" root directory. In this case we need to run javac
with the class path parameter "-classpath c:\javalib" and specify the source file "AreaTest.java".
Remember, in bare javac this was done with the complete command line
"javac -classpath c:\javalib AreaTest.java". Also note that we could get away with not feeding the
whole file path of "AreaTest" because our Dos window was already set to that directory.
In textpad, with "$File" representing our sourcecode file (AreaTest.java) including the full path, we
now add the class path option to this parameter to javac by setting the parameter from "$File" to
"-classpath c:\javalib $File".
This translates to the command line statement of "javac -classpath c:\javalib c:\myprog\AreaTest.java",
which is exactly what we want.
java tool alone
Bare java expects to find all the necessary class files in the current directory, so we could run
"AreaTest" from a dos window set the "c:\myprog" by typing "java AreaTest". This causes java to seek
the program "AreaTest.class" from the current directory. If, however, we placed our package file in
another directory as in our first example (rogerslib placed in javalib folder in c:\), we would have
to set the class path. Here we would type:
"java -classpath c:\javalib;c:\myprog AreaTest".
Look at this line carefully so you understand what is actually taking place. Once we start telling
java tool where our classes are, we must specifically tell it where ALL of the class files can be
found. If we just told it that classpath was "c:\javalib", and then told it to run "AreaTest", it
would assume that "AreaTest.class" was also located in "javalib" and this is not true. This is why the
line "java -classpath c:\javalib AreaTest" will return error. We must fully declare all class paths,
which includes the location of the main program class, "AreaTest", which is still in "myprog". We do
this by giving the classpath option multiple arguments (in this case two of them). This is done by the
segment of the command line "-classpath c:\javalib;c:\myprog". Here we are giving two class paths
separated by the ";" character as described in java documentation.
java tool with textpad
Now that we understand bare java, we are ready to run it in textpad. Just as no changes were
required from the default setting in textpad for compiling with all class files in the default
directories, there is no need to alter textpad's default for running the application. Go to
textpad's "run application" parameter settings just as you found the javac parameter
(Configure -> Preferences) click on the "+" by "tools", but this time select "Run Java Application".
For the default parameter for the "java" tool you see "$BaseName". This is defined by the help doc as
"$FileName, stripped of any extension". This would therefore be the equivalent command line of
"java AreaTest". Since all class files are in the current directory this would run fine.
Now lets use our example again where we move class files out of their current directory. Again we
will seek out the package "rogerslib" in the directory "javalib". We know from our discussion of bare
java that java is seeking the class path and the file name of the main program class as parameters.
Therefore we will set our parameter from the default of "$BaseName" to:
-classpath c:\javalib;$FileDir $BaseName
Here we use "$FileDir" which is defined in the help doc as
"The drive and directory of the current document". Assuming we have "AreaTest.java" loaded in textpad,
when we now choose "run java application" from the tools menu, this parameter setting is the equivalent
of "java -classpath c:\javalib;c:\myprog AreaTest". This will work fine and is precisely what we want,
as it conforms to the successful command line we used in our 'bare java' example just before.
Hopefully this will clear up some of the confusion regarding class path settings using the tools by
themselves and within textpad.
John Rogers
jrogers@pclink.com
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact: