The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix mailsukumar Shell Programming and Scripting 0 05-26-2008 05:12 AM
Newbie Question: passing a variable into java from script? Cailet Shell Programming and Scripting 1 10-18-2007 06:31 PM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 3 09-14-2006 07:23 AM
Newbie to Unix Mafia UNIX for Dummies Questions & Answers 8 10-15-2002 01:42 PM
unix newbie gavinlow1980 UNIX for Dummies Questions & Answers 1 12-20-2001 05:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2005
uci uci is offline
Registered User
 

Join Date: Mar 2005
Posts: 3
Question newbie need help to run java in UNIX

I need to run .java from a directory.

i.e. c:\aaa\bbb\ccc.java

first I compile all the java using javac *.java under the c:\aaa\bbb directory, now I want to run this command under cd .. ,

Here is the command that I need to type..

java -classpath /home/share/postgresql/java/postgresql.jar:. ccc

What do I need before ccc in order run ccc.java under the parent directory?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-09-2005
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,434
Just amend the classpath to add the path where java can find ccc.class
Reply With Quote
  #3 (permalink)  
Old 03-09-2005
uci uci is offline
Registered User
 

Join Date: Mar 2005
Posts: 3
Quote:
Originally Posted by cbkihong
Just amend the classpath to add the path where java can find ccc.class
How do I do it? Could someone please tell me what to add into this command

java -classpath /home/share/postgresql/java/postgresql.jar:. ccc
Reply With Quote
  #4 (permalink)  
Old 03-09-2005
Registered User
 

Join Date: Nov 2004
Posts: 68
You need to set you enviroment to reflect these:

setenv CLASSPATH /home/share/postgresql/java

or

set CLASSPATH=/home/share/postgresql/java; export CLASSPATH

Ensure that you JAVA_HOME is also define so you could execute any java programs from anywhere.

You may want to add them to your .bashrc or you .cshrc or what ever shell you are using.
Reply With Quote
  #5 (permalink)  
Old 03-09-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
type

java on the command line and see what options do you have.

for classpath you have to append the class name for java
to find ccc.class.

and for classpath each jar or class is seperated by ; in windows and : in unix.

Since You are on windows ... try this.

Code:
java -classpath /home/share/postgresql/java/postgresql.jar;PATHOFCCC/ccc.class  ccc
Or do the same thing in by setting CLASSPATH environment variable.

in windows

set CLASSPATH=%CLASSPATH%;PATHOFCCC\ccc.class

and run ccc.class as

java ccc





In unix ,
export CLASSPATH=$CLASSPATH:PATHOFCCC/ccc.class

and

java ccc
Reply With Quote
  #6 (permalink)  
Old 03-09-2005
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,434
Usually I just set the classpath as an option to the java or javac command, instead of setting the CLASSPATH environment variable because it is likely that running/compiling one Java program needs a classpath different from another. Setting this environment variable overrides the default classpath up until the current session terminates. Sometimes you may not realize this environment variable is set, but somehow it has been defined somewhere, and you may get lots of classpath errors despite there should not be if it is not set (I have seen articles telling people to set the CLASSPATH in shell startup scripts, like .profile and the like).

A better way to manage all these is to write an Ant build file, similar to the concept of Makefiles, which has directives to override the list of classpaths. You can write a build file with two targets, one to compile it and another to run it. Then you can avoid a lot of troubles thereafter for writing really loooooong command-line arguments, as Ant knows how to compose the exact commands for you. It is particularly handy for projects that need to override the build paths.

More info? http://ant.apache.org
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0