newbie need help to run java in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers newbie need help to run java in UNIX
# 1  
Old 03-09-2005
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?
# 2  
Old 03-09-2005
Just amend the classpath to add the path where java can find ccc.class
# 3  
Old 03-09-2005
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 Smilie

java -classpath /home/share/postgresql/java/postgresql.jar:. ccc
# 4  
Old 03-09-2005
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.
# 5  
Old 03-10-2005
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
# 6  
Old 03-10-2005
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with writing a script to run java commands in sequence in UNIX

Hi, Brand new to these forums, and I hope that someone can help me out. I'm trying to run the following command in UNIX java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my.bam --outputRoot /my/path/SampleFiles/Sample_ It executes the SplitSamFile from GATK, but I... (3 Replies)
Discussion started by: Wixaros
3 Replies

2. UNIX for Dummies Questions & Answers

How to compile and run java in UNIX?

Hi Im using MobaXterm Unix on my windows XP.I want to compile java in unix.I have installed java to the following path C:\Program Files\Java\jdk1.7.0_09\bin In order to compile the java prog im typing the following command after entering into the bin directory: C:\Program... (2 Replies)
Discussion started by: ak3141
2 Replies

3. Shell Programming and Scripting

How to run java from shell

Hi All, I am trying to run a grep command which creates an output file. Then I will run a java file which take that file and process that. My java file uses other java files and library jars. I have tried below code but I am getting compilation error,it can not find other java files in same... (1 Reply)
Discussion started by: kmajumder
1 Replies

4. SuSE

HELP for Newbie: Unable to run GUI installer (Ubuntu client connected to SLES server)

Hello All, I'm using my Ubuntu 10.04 client connected via SSH to a SuSE Linux server (SuSE Linux Enterprise Server 11 (x86_64) version 11 patchlevel=1). I'm trying to run an install of WebSphere Portal but can't seem to be able to run the GUI installer. Running xclock as root returns this... (7 Replies)
Discussion started by: kartrait
7 Replies

5. Solaris

Java Run Time

I have installed IBM Java Runtime V1.4.2 in solaris. but when i give java -version, it gets me this:java version "1.5.0_20" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02) Java HotSpot(TM) Client VM (build 1.5.0_20-b02, mixed mode, sharing) can you please tell me how do i... (3 Replies)
Discussion started by: ichwaiznicht
3 Replies

6. Programming

Run Unix commands from Java

Greeings all Im trying to excute a command from Java and direct the output to the main output screen or to another file .... can you please help with this ? can I use filewriter for this ? Here is my code.... import java.io.BufferedReader; import java.io.File; import java.io.FileWriter;... (3 Replies)
Discussion started by: yahyaaa
3 Replies

7. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

8. Shell Programming and Scripting

Newbie Question: passing a variable into java from script?

I'm currently working on my second ever ksh script! So I apologize if this is a stupid question - I've searched the forum and on google and haven't seen anything :confused: I'm running my script with an input at startup that variable determines a couple of other values(int) that I store into... (1 Reply)
Discussion started by: Cailet
1 Replies

9. UNIX for Dummies Questions & Answers

Run the start script from the terminal? Newbie Time!

Hi, How do I "run a script"? I'm trying to start up some software called ElectroServer 3, and was told I just needed to "run the start script from the terminal to get things going". From the terminal, i use cd command to change to the software's directory, and I guess the script in question is... (4 Replies)
Discussion started by: waking_bear
4 Replies

10. UNIX for Dummies Questions & Answers

run a java file on UNIX?

HI, I want to run my .java file on a SunOS 5.8 Unix machine. The java file is writen with Ready to Program (Similar to Jbuilder) on a PC. Thanks!! (3 Replies)
Discussion started by: leotopia
3 Replies
Login or Register to Ask a Question