How to run java from shell

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run java from shell
# 1  
Old 08-27-2012
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 directory. Please suggest?

grep -e keyword1 test.txt -e keyword2| cut -f 2,5,14 | sort| uniq |awk '{$1=$1;print}' OFS=,> /Users/kmajumder/Documents/Shell/java/com/test/opcomma.xls

export CLASSPATH=$CLASSPATH:/Users/kmajumder/Documents/Shell/java/lib/*.jar:/Users/kmajumder/Documents/Shell/java/com/test/*.java

javac /Users/kmajumder/Documents/Shell/java/com/test/
java /Users/kmajumder/Documents/Shell/java/com/test/Test.class

Thanks in advance.
# 2  
Old 08-27-2012
Originally Posted by kmajumder
export CLASSPATH=$CLASSPATH:/Users/kmajumder/Documents/Shell/java/lib/*.jar:/Users/kmajumder/Documents/Shell/java/com/test/*.java

I am not all that knowledgeable about Java, but AFAIK "CLASSPATH" is a PATH, as the name suggests. Remove the superfluous (and probably dangerous) shell globs ("/*.jar", "/*.java") from your definition and try again.

I hope this helps.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

How to run the Shell Script from external directory using java?

Hi, I have created a Shell Script and invoke through java using Process Builder It's working fine, if (Shell script file ) in the same directory as java file. By Problem: How to run the Shell Script file( resides in external directory) using java. What configuration i have... (1 Reply)
Discussion started by: nanthagopal
1 Replies

3. UNIX for Advanced & Expert Users

java compile and run program help

What is the trick to get a java program to run and compile? I can't even get a basic skeleton to run and compile. What packages do I need? I figured the java-gcj and gcc-java packages was enough. Do I need any other packages? I thought I had to do this and it would work but its not. javac... (1 Reply)
Discussion started by: cokedude
1 Replies

4. 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

5. UNIX for Advanced & Expert Users

run shell script in java?

hi, how to run shell script in java? i have script which takes 1 argument as input and returns exit code integer. how to handle it in java. should i have to invoke process to execute it and then wait til it completes ? please explain with code thanks (1 Reply)
Discussion started by: crackthehit007
1 Replies

6. UNIX for Dummies Questions & Answers

trying to compile and run java through the terminal

Hey everybody, Ok here is my problem. I have this code that that compiles, but when i go to run it it gives me errors. I stored my simple java class here: /user/workspace/getMailFromSafeDoc/src I store my mail.jar file here: /user/workspace/getMailFromSafeDoc/lib/javaMail/javaMail.jar ... (2 Replies)
Discussion started by: killesk
2 Replies

7. UNIX for Dummies Questions & Answers

Trying to run java file in crontab

Hi. I have a java program that create reports, and I would like to run it at each hour using crontab. The main file is crome.jar located at /WebApps/Crome folder. When I want to execute the program I use the next script (name crome): #!/bin/sh if ; then ... (1 Reply)
Discussion started by: karmariv
1 Replies

8. Shell Programming and Scripting

how can i run java program from any where

Hello all sorry didnt know where to post it 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... (1 Reply)
Discussion started by: umen
1 Replies

9. 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

10. UNIX for Dummies Questions & Answers

run java using shell script

I have written a java file which runs fine when I compile and run it from the command prompt manually. i.e, >javac >java z I have put these two lines in a executable file. But when I run the executable file, it throws an error 'Thread Exception'. Any thoughts? #executable file... (1 Reply)
Discussion started by: inpavan
1 Replies
Login or Register to Ask a Question

Featured Tech Videos