Compiling Java Works, Executing Java Doesn't

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Art Metzer
Posts: 27
Joined: Mon Mar 06, 2006 5:31 pm

Compiling Java Works, Executing Java Doesn't

Post by Art Metzer »

I'm having problems getting even the simplest of Java programs to run on TextPad 7.

I am running Windows 7 SP 1, 64-bit.

My Java version is 1.7.0_40.

My Ctrl + 1 tool is "Compile Java". This part is working. Under the "Compile Java" tool, I have a Command of:
C:\Program Files\Java\jdk1.7.0_40\bin\javac.exe
and Parameters set to:
-classpath "$FileDir;C:\Users\ArtMetzer\Documents\Technical\Java" $File
and Initial folder set to:
$FileDir
The following code makes up C:\Users\ArtMetzer\Documents\Technical\Java\HelloWorld.java:

Code: Select all

public class HelloWorld {

    public static void main( String[] args ) {

        System.out.println( "Hello World" );
    }
}
When I choose the "Compile Java" external tool, the Tool Output reads "Tool completed successfully", and I can see that the file C:\Users\ArtMetzer\Documents\Technical\Java\HelloWorld.class has been created.

However, when I go on to choose the "Run Java Application" external tool, the Tool Output reads:
Error: Could not find or load main class C:\Users\ArtMetzer\Documents\Technical\Java\HelloWorld.java

Tool completed with exit code 1
Here are the values I have specified for the "Run Java Application" tool:

Command:
C:\Program Files\Java\jdk1.7.0_40\bin\java.exe
Parameters:
-classpath "$FileDir;C:\Users\ArtMetzer\Documents\Technical\Java" $File
Initial folder:
$FileDir
What do I need to change, or what do I need to look into, to get my Java program(s) to execute?

It seems like the java.exe executable should be executing C:\Users\ArtMetzer\Documents\Technical\Java\HelloWorld, and not C:\Users\ArtMetzer\Documents\Technical\Java\HelloWorld.java?

Thanks,

Art.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The interpreter uses the class path to find your classes: you specify only the name of the class file, not its directory.
And you don't specify the class file's extension.
So what you need is
-classpath "$FileDir;C:\Users\ArtMetzer\Documents\Technical\Java" $BaseName
Art Metzer
Posts: 27
Joined: Mon Mar 06, 2006 5:31 pm

Post by Art Metzer »

That worked! Thanks, Ben.

Art.
Post Reply