• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i run program from any where (unix alert!!)  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
i compiled simple program that using "System.getProperty("user.dir");"
now i compiled the program under directory foo and and its running great when i do "java myapp"
i included this directory in the $PATH env variable so i could see it fro any where in the system
but now when i try to run this java app from other place in the file system with "java myapp" it gives me "Exception in thread "main" java.lang.NoClassDefFoundError:" erorr . why is that ?

Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The $PATH enviroment variable is not what you need to set for this. You need to set $CLASSPATH
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so do i need from every place i run my app to include in the $CLASSPATH?
this is lots of work , or do i have somekind of global method?
thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
$CLASSPATH is an environment variable just like $PATH. You set it once, in your login script for example, and you won't have to type it in anytime you start your Java application.

You can ofcourse also write a two-line shell script to start your Java application, which contains the command line including the classpath, so you don't have to type it in every time. Example shell script:

#!/bin/sh
java -classpath /usr/home/myaccount/myjavadir com.mypackage.MyMainClass
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!