• 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

Installation Problem-Help with running compiled code in command line.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have installed JDK7 on my machine and have pointed to the bin directory in the classpath and path in the system environment variables by copying the location of the bin directory. My code compiles but it does not run. I keep getting the error in command line saying "could not find or load main class proceduraljava.HelloWorld". Proceduraljava.HelloWorld is class compiled in the bin folder. Everything was created fine, the source and bin folder and even the source and compiled code but it just won't run. I have unstalled and re-installed countless number of times but still get the same error. Please help!

Samuel.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You can usually do more harm than good by setting a system Classpath. If you have just set the classpath yourself, I suggest you unset it. If the classpath was set before you installed Java, add a dot for “current directory” to it.
Don’t put your work into a bin directory. Create yourself a directory like this

mkdir java
cd java

... or similar. You can now reach the directory with the cd instruction next time you open the terminal. Put all your work into that directory.
If you are new enough to be writing Hello World programs, omit the package name from your code; that makes it much easier to find the .class files.
 
Samuel Bee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for your reply. I am very new to Java programming. I did not put all my work in the bin directory. Here is what I did.

I created a project directory,PAP. Then I created three directories, src, bin and data within the project directory.



I created a directory, proceduraljava in src. Then I created a file, HelloWorld.java in proceduraljava using a text editor to edit HellowWorld.java so that
it contains this class definition.




Then the directory structure looked like this.



I opened the command line interface/terminal and navigated to the src file. I compiled HelloWorld.java with the command "javac -d ../bin proceduraljava/HelloWorld.java".

The file structure then looked look like:



I saved the file (code) in the source folder but it automatically compiles into the bin folder.
I navigated the terminal to bin and tried to execute "HelloWorld" with the command "java proceduraljava/HelloWorld" but the problem is it won't run.
I tried unsetting the classpath and adding a dot for the ""current directory" and also omitting the package name in the command line as you suggested but it still won't run.
It still comes up with the same error message. I have spent almost 2 weeks on this with no luck. I don't know what I'm doing wrong. Please help!


Samuel.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you got that bin directory in the first place? The JVM and compiler will not use that folder at all.
How are you invoking the HelloWorld class?
 
Samuel Bee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Funny enough this works on some machines (Window XP and Windows 7 32bits systems) but I don't know if it's because I have Window 7 64 bits system. Also,I read a documentation on oracle.com about installation of JDK 7 and it says that you have to add the bin directory to the path variable.
Instruction below.

To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.7.0\bin. Set the PATH variable as follows on Microsoft Windows:
1. Click Start, then Control Panel, then System.
2. Click Advanced, then Environment Variables.
3. Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable:
C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0\bin
Note:
• The PATH environment variable is a series of directories separated by semicolons (;) and is not case-sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored.
• If you are not sure where to add the path, add it to the right of the value of the PATH variable.
• The new path takes effect in each new command window you open after setting the PATH variable.

Excerpt from java tutorials

It looks like the bin folder contains all the applications needed to run java on any machine (see the java installation folder). I don't know what is really wrong. The system recognises java and even compiles correctly but it just won't run.
 
Samuel Bee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Many thanks Campbell. My system now runs the code. I think unsetting the classpath and just adding a dot for the "current directory" to it as you suggested solved the problem. I only discovered it worked after I restarted my computer. Thanks


Samuel.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome I always forget to say you have to restart the command line before the new settings take effect.
reply
    Bookmark Topic Watch Topic
  • New Topic