• 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

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

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The $PATH enviroment variable is not what you need to set for this. You need to set $CLASSPATH
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic