This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Running class file from command line fails: "Error: Could not find or load main class"

 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm trying to compile & run a Java file from the command line.

Compiling seems to work fine, but running fails. I read some of the other topics on here with a similar issue, but none of the proposed solutions seem to work for me.

These are the commands I tried (note: I have no CLASSPATH environment variable set.)



This is CompileMe.java:



Does anyone have an idea what I'm doing wrong here?
 
Saloon Keeper
Posts: 6040
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you want to change your working directory to
C:\Eclipse workspaces\notes\oca
And then run
java book/CompileMe

Are you actually using Eclipse for your project? If so, you can run your program by highlighting the .java file and selecting Run as > Java application.
 
Bjorn Jansen
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I think you want to change your working directory to
C:\Eclipse workspaces\notes\oca
And then run
java book/CompileMe


Ah, changing it to C:\Eclipse workspaces\notes\oca\src worked!


Are you actually using Eclipse for your project? If so, you can run your program by highlighting the .java file and selecting Run as > Java application.


I know, but I'm working through the OCA-study guide and I'm just trying to reproduce some of the things I read there.

Anyway, thanks for the help! I knew the solution would be something easy/obvious...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I think you want to change your working directory to
C:\Eclipse workspaces\notes\oca
And then run
java book/CompileMe

Are you actually using Eclipse for your project? If so, you can run your program by highlighting the .java file and selecting Run as > Java application.



Thank  I had the same problem ))
 
Marshal
Posts: 65050
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch It is good to see that old threads can still be useful.
 
Marshal
Posts: 6970
471
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch It is good to see that old threads can still be useful.


Welcome to the Ranch again Indeed, the more - better. We love to iterate things over and over again, so every mind could find right explanations which work for them.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!