• 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

Question about java and javac commands

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my layout

-> /home/name/myProject
-> inside myProject are subdirectories named sources and classes
-> inside sources there is com/test
-> inside test there is MyClass.java with a package declaration in file package com.test;

I changed my directory to myProject and invoked the command

As it was expected it created classes/com/test/MyClass.class

Here is my question. I have tried to invoke the java command to run Test.class.

When I'm in myProject, thats /home/name/myProject

java -cp /home/name/myProject/classes/test MyClass //full path, i get NoClassDefError
java -cp classes/com/test MyClass //relative, i get NoClassDefError

How am I gonna run it?

Regards,



 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not completely sure you compiled it correctly, but assuming that you did, the command should be....

java -cp /home/name/myProject/classes com.text.MyClass



The purpose of the classpath is to specify the top of the root -- which is /home/name/myProject/classes. And you need to specify the fully qualified name of the class, which is com.text.MyClass.

And this should work anywhere. If you want to do it without specifying the classpath... You can either set the CLASSPATH environment var, or just work from the root.

cd /home/name/myProject/classes
java com.text.MyClass



Henry
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic