Starting Java Program with a bash Shell script

Hi !
I know this is a Linux query but I am putting it on this site to get different answers.
I want to start my Java program with a shell script. Can anybody give me a proper script to start my Java program?
I am using RH Linux 7.3 and JDK 1.4.
Can I start the Java program without starting the terminal? Just like the Sun One Studio4 'runide.sh' script.
Please help.
Bye Niteen

assuming you have your PATH and CLASSPATH variables set correctly, your script should look like this:
#!/bin/bash
cd <project_dir>
java <class> &
example:
#!/bin/bash
cd ~/projects
java project1.main_package.MainClass &
of course you could add some more elaborated stuff like compiling files before running the program, etc.
if you dont like terminals, try running "nautilus" (it's like Windows Explorer). i never use nautilus (especially for running scripts), so i cant guarantee it will work, although i dont see why it shouldnt...

Similar Messages

  • Problem with running Bash shell scripts

    I am unable to run Bash shell scripts on the UNIX Terminal application.
    This is the transcript from the Terminal application.
    Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$ ./test1.sh
    dyld: Symbol not found: _BC
    Referenced from: /usr/local/bin/bash
    Expected in: /usr/lib/libSystem.B.dylib
    Trace/BPT trap
    Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$
    Is this a problem with the the default installation of the Bash shell? Can I install the Bash shell on my own? If so, how can I do that?
    Also, how can I get the dynamic linker, dyld, to refer to the symbol "_BC"? What does this symbol "_BC" refer to?

    This was in your posted output:
    /usr/local/bin/bash
    You are NOT running the default bash, you are trying to run a private copy.
    The default Mac OS X bash is located at
    /bin/bash
    Try the following:
    /bin/bash ./test1.sh
    Does that work?
    What is the first line of your script? Is it:
    #!/bin/bash
    Or maybe
    #!/usr/bin/env bash
    /usr/bin/env would find the first bash in PATH . I find this most useful for finding perl on different systems, but sh, ksh, bash, zsh, csh, tcsh are all generally found in /bin so I do not bother using /usr/bin/env
    And if you have
    #!/usr/local/bin/bash
    Then the person that wrote test1.sh choose to use something besides the default bash
    Or maybe this script was transferred from some system where you needed to put your own copy of bash in /usr/local/bin because the vendor does not distribute bash
    Then again, you have not showed us what is inside your script, so it is possible something in the script called something else which invoked the /usr/local/bin/bash
    If that is the case, then you might try:
    /bin/bash -x ./test1.sh
    which should show you the commands executed before it died.

  • Error in calling SQL plus program with parameter from Shell script

    This is my Shell script. I am trying to call in the SQL plus program with the parameter and the shell script is registered as a concurrent program.
    PARAMETERS=`echo $1 |tr -d '\"'`
    DB_USER_ID=`echo $PARAMETERS|cut -d" " -f3|cut -d"=" -f2`
    CONN_STRING=$DB_USER_ID
    REQ_DATE=`echo $PARAMETERS|cut -d" " -f9|cut -d"=" -f2`
    timestamp=`date +%m-%d-%y-%H:%M:%S-%Z`
    timestam=`date +%y-%m-%d`
    sqlplus -s $CONN_STRING @ar_statement.sql $REQ_DATE
    chmod 755 statement.sh
    . statement.sh
    My Sql plus program is like this.
    set pagesize 0
    set heading off
    set feedback off
    spool $GEC_TOP/log/ge_ar_statement.sh
    select output_file_name
    from fnd_concurrent_requests
    where trunc(actual_completion_date) = '&2';
    spool off;
    exit;
    When i run the concurrent program, i am getting the following error:
    ar_statement: line 14: REQ_DATE: command not found
    Enter value for 2:
    User requested Interrupt or EOF detected.
    ar_statement.sh: line 1: Enter: command not found
    ar_statement.sh: line 2: User: command not found
    ar_statement
    Program exited with status 127
    I am not strong at Unix Porgamming and i would request someone who can
    help me out as soon as possible.
    I need this solution quickly and thank everyone in advance.
    Thanks.

    Can you put your coding between code statements, like shown in the FAQ. It will be easier to read.
    Looking at your script, my first guess is that crontab will not find your sqlplus since your script does not have $HOME/bin in the $PATH. From what I understand, running .profile in your script will not work either because variables are exported to sub-shells, not to the shell above. You can call your script with a dot like . ./script which means that the script will run like it was typed at the command prompt. But it will be less confusing to define appropriate variables in the script. eg.
    ORACLE_SID=my_instance_name
    ORACLE_HOME=/my_path_to_oracle_home_directory
    LD_LIBRARY_PATH=$ORACLE_HOME/lib
    PATH=$ORACLE_HOME/bin:$PATH
    I remember some slightly different way of coding to handle the sqlplus return codes.
    For instance:
    sqlplus -s /nolog > /dev/null <<-EOF
    connect system/manager
    @ssm.sql
    whenever oserror exit failure
    whenever sqlerror exit failure
    EOF
    sql_err=$?
    if [ $sql_err -ne 0 ]; then
       echo "FAILURE"
    else
       echo "SUCCESS"
    fiThe - in -EOF supresses tab's
    Using connect will prevent ps from showing your login credentials
    In some versions of bash the ending EOF needs to be at the beginning of the line to work.
    Edited by: waldorfm on Jul 14, 2010 7:05 PM
    complaining about putting code between code delimiters and forgot myself ;-)
    Edited by: waldorfm on Jul 14, 2010 7:08 PM
    Btw, if you "source" a script running it like . .script, than an exit in that script will log you out.

  • Invoking a bash shell script from Java code

    Hi All
    I am trying to invoke a Bash shell script using java code. The arguments required are "source wmGenPatch <source dir> <destination dir> no_reverse.
    in the code I have specified the arguments considering the cannonical paths of the files as the code may run on Unix or windows platform.
    I am getting a error while invoking Runtime.getRuntime().exec(args). The error is as follows :
    "The Error Occurred is: CreateProcess: source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=2"
    It seems that error=2 indicates that the 'file not found' exception. But i can see the directories referred to in the error at place in the workspace.
    Kindly advice.
    Thanks in advance.

    Hi All
    I am pretty new to invoking bash shell scripts from java and not sure if i am progressing in right direction.
    The piece of code tried by me is as follows
    try {
                   currentDir = f.getCanonicalPath();
              } catch (IOException e) {
              if (currentDir.contains("/")) {
                   separator = "/";
              } else {
                   separator = "\\";
              String args[] = new String[7];
              args[0] = "/bin/sh";
              args[1] = "-c";
              args[2] = "source";
              args[3] = currentDir + separator + "DiffEngineScripts" + separator
                        + "v4a02" + separator + "wmGenPatch";
              args[4] = sourceFileAdd;
              args[5] = destFileAdd;
              if (isReverseDeltaRequired) {
                   args[6] = "reverse";
              } else {
                   args[6] = "no_reverse";
              try {
                   Process xyz = Runtime.getRuntime().exec(args);                              
                   InputStream result = xyz.getInputStream();
                   InputStreamReader isr = new InputStreamReader(result);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ( (line = br.readLine()) != null)
                        System.out.println(line);
                   int exitVal = xyz.waitFor();
                   System.out.println("Leaving Testrun.java");
              } catch (Throwable t) {
                   t.printStackTrace();               
    and on running the same i am getting Java.io.IOException with the stack trace
    java.io.IOException: CreateProcess: \bin\sh -c source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=3
    kindly advice
    Thanks in advance

  • Exit status running java classpath in a unix shell script

    I'm new to putting java into unix scripts. I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.
    notifycode=$?
    echo $notifycode
    I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.

    That's Java code, it says "End this Java application and send return code 1 back to the shell". As for how the shell gets the return code from the application, that's a question about your shell and not about Java programming, no?

  • How to start java applet with netbeans 6.1

    hey,
    I want to learn how to start java applet (with database) with netbeans.. I'm new to java...can you show me how can i start..if you have any doc about it can you send it to me..thank you..:)

    You really should be asking this NetBeans question at the NB site - these forums are for Java language topics, not NB support.
    [http://www.netbeans.org/kb/61/web/applets.html]
    Almost any NB question you have can be answered by either the NB web documentation or the NB program's Help.

  • Getting an exit value from a program called thru a shell script

    how do i get the correct exit value always from a program called thru a shell script
    the getExitValue of the process works fine someitmes but not always ...
    Ex: write a pgm which sleeps for 5 secs & returns with exit(100).try to invoke this thru a script & try to run this script from Runtime.getRuntime.exec(..)
    ...the exit value is not same as 100.(it works if the sleep is not given though !!)
    can nebody help??

    ive done that ...see the sample code for ex..
    public void execute()
                   try{
                             Process program=Runtime.getRuntime().exec(cmd);
                             printOutput(program.getInputStream());
                             try
                                  program.waitFor();
                             catch(InterruptedException e)
                                  System.out.println("Command Interrupted: " + e);
              System.out.println("Error status : "+program.exitValue());
                        catch(SecurityException e)
                             System.out.println("Error executing program "+e);
                        catch(IOException e)
                             System.out.println("Error executing program "+e);
    ....

  • Interfacing a java program with hardware

    I need to be able to interface a java program
    with data in the parallel or serial ports of the computer.
    I have no idea how to go about this, could someone please help me.
    Thanks

    http://java.sun.com/products/javacomm/

  • How can i run my java program with out java language

    Hai to every one ..Iam new to java language ...am using windows xp operating system , i did not installed java language in my system .. how can i run a java program with out installing java language... Which files is requied to run java program..?
    any one can help me??

    Hai to every one ..Iam new to java language ...am
    using windows xp operating system , i did not
    installed java language in my system .. how can i run
    a java program with out installing java language...
    you ... can ... not ... do ... this
    Which files is requied to run java program..?
    any one can help me??a JVM. Download it from sun's website.
    [url http://java.sun.com/javase/downloads/index.jsp]Download JavaSE here

  • How to run a standalone java program with JRC to display/run a report

    Hi All,
    I am new to this forum.
    I am trying to run a java program developed using JRC to run a report created using Crystal Report XI. I stucked because not knowing how to run that java program.
    Can anyone help me? or
    can give a simple java code to do the same.
    Thanks in advance.
    Saravanakumar.

    Hi Saravana
    For the steps to run a standalone application java program with JRC to display/run a report ,please refer the following link.
    http://support.businessobjects.com/communityCS/TechnicalPapers/cr_xi_r2_jrc_deployment.pdf.asp
    You can get the sample code for standalone/desktop applications from the following link.
    http://support.businessobjects.com/communityCS/FilesAndUpdates/crxi_r2_jrc_desktop_samples.zip.asp
    Please do revert in case of any queries.
    Thanks
    Soni

  • How do you start a java program with more RAM alloaction

    Hi
    can anyone please tell me how to start a java program to start with lots of RAM (RAM size is sent as a parameter), I have seen it somewhere and now I cant remember it. I have a server application to run this way.
    thanks and rgds
    sunil

    see the tooldocs of java: http://java.sun.com/j2se/1.4/docs/tooldocs/tools.html

  • ASP code to start a Java program (with parameters)

    Hi! All,
    I am trying to write some ASP code which should start a java program. Does anybody know a simple way to do this? Am new to ASP
    Thanks

    It doesn't have anything to do with java.
    Basically you need to make a system call which will start an external application. The external application can be anything including something like "java MyClass".
    So either find an ASP forum/board/newsgroup to ask how to do a system call or read some docs on it.

  • Bash shell script to exception when database has been shutdown

    Hi, I'm quite new in shell scripting. I created the below simple script to do a check on the database, it's a count so it works fine... if the database is there. Now I want to be able to catch if the database is or is not there, what I tried so far didn't work, can anybody please give me a hand with this?
    The shell script file "start_check.sh":
    #!/bin/bash
    # Set environmental variables
    . /home/oracle/env/usrdwh1.env
    TEMP_FILE=rwcnt
    runCheckQuery()
    # Run query and dump result into the TEMP_FILE
    sqlplus -s "/as sysdba" > /tmp/${TEMP_FILE} << EOF
    @/u02/reports/sql/start_check.sql
    EOF
    if [ $? -eq 0 ]
    then err_num=0
    else err_num=1
    fi
    ################ MAIN ####################
    runCheckQuery
    row_count=`cat /tmp/${TEMP_FILE}`
    if [ $err_num -eq 0 ]
    then
    # If no rows were found then send an email alert
    if [ $row_count -eq 0 ]; then
    echo 'No process found - Please investigate' | mailx -s "Daily check ALERT" [email protected]
    fi
    else
    # There was an error when trying to connect to the db. Need to report it
    echo 'Database connection error - Please investigate - Error Message: (' $row_count ')' | mailx -s "Daily check ALERT (Database connection error)" [email protected]
    fi
    # Remove the tmp file
    rm /tmp/${TEMP_FILE}
    The sql script file "start_check.sql":
    SET SERVEROUTPUT ON
    SET FEEDBACK OFF
    WHENEVER SQLERROR EXIT;
    DECLARE
    row_count NUMBER;
    BEGIN
    SELECT COUNT(*)
    INTO row_count
    FROM dw_ml_ba ml_ba
    WHERE sys_id = 'CCX'
    AND ml_ex_start_datetime > TRUNC(sysdate);
    DBMS_OUTPUT.PUT_LINE(row_count);
    END;
    EXIT
    Edited by: leocoppens on Jan 4, 2013 4:05 PM

    There may be a better, but here is a shell script that works:
    #!/bin/ksh
    # db_check.sh
    # Script used to check if one or all of the databases on
    # one server are available.
    # Parameter Description
    sid=$1    # Database SID or Keyword 'all'
    function check1db
    sid=$1    # Database SID
    ORAENV_ASK=NO
    . /usr/local/bin/oraenv "$sid"
    ORAENV_ASK=YES
    if [ $(ps -ef|grep "ora_smon_$sid"|grep -v grep|wc -l) -eq 0 ]
    then
      echo "%-Error, Database $sid is NOT available - Not started\n" >>${CHKLOG}
      return 1
    fi
    dbok=$(\
    sqlplus -s / <<!
    if [[ $(echo $dbok|cut -d' ' -f1 ) == 'ERROR:' ]]
    then
      echo "%-Error, Database $sid is NOT available - Started with errors\n" >>${CHKLOG}
      return 1
    else 
      echo "%-Info, Database $sid is available\n" >>${CHKLOG}
    fi
    return 0
    } # end function check1db
    # Set some environment variables:
    ORACFG=/etc               # Location of oratab
    ORALOG=$HOME/logs         # Location for result log
    EMAIL='[email protected]'  # E-mail to send alert
    sid=${sid:-'all'}
    echo "$0 Job started at: `date` "
    BDATE=$(date +%y%m%d)
    export CHKLOG=$ORALOG/db_check_${sid}_${BDATE}.log
    echo "$0 on `date`" >$CHKLOG
    if [ "$sid" = "all" ]
    then
      i=0
      stat=0
      cat $ORACFG/oratab | while read LINE
      do
        case $LINE in
         \#*)            ;;      #comment-line in oratab
            sid=`echo $LINE | awk -F: '{print $1}'`
            check1db "$sid"
            stat1=$?
            ((stat += $stat1)) # Combine the Status of All Calls
            ((i = $i + 1))     # Count Number of Databases Checked
        esac
      done
      ((j = $i - $stat))  # Count Number of Databases Available
      echo "\n%-Info, `date +%c`,\n\tTotal databases checked = $i,\n\tAvailable = $j, Not available = $stat\n" >>${CHKLOG}
    else
      check1db $sid
      stat=$?
    fi
    # Beep operator if database down.
    if [ ${stat} -ne 0 ]
    then
      SUBJ="Database(s) alert."
      mailx -s"$SUBJ" $EMAIL <$CHKLOG
    fi
    echo "$0 Job stoped at: `date` "
    exit $stat:p

  • Running java program with arguments in Unix

    Hi
    I am a new newbie to java so pardon if this is too simple for you .
    This is my scenario. I have a java program which parses an xml and writes a .dat file. I execute this testparser.java in unix environment like this
    java testparser xml1.xml
    and it retuns me a .dat file
    But my issue is I have to run my parser program for 40 xml files. The requirement is I have to create a script file and possibly with a for loop which will loop through 1-40 xml files and return me the .dat file.
    I am really at a loss here. I am new both to Java and Unix
    So pls help me out
    Thanks in Advance
    G

    You could just do this in Java. Make it take all 40 xml files on the command line, and convert them all with one program invocation.
    If you want to do it in shell script, you can do something like
    for tmp in `ls -1 *.xml`; do
      java testparser $tmp
    donedepending on your shell, etc.

  • Invoking a Package.Procedure via bash shell script

    Hello All,
    I am using the below syntax to call package in a unix shell script, is this right way of calling and checking for errors or is there any other better approach?? kindly suggest.
    I am using Oracle 11g & Linux OS, SQL*Plus: Release 11.2.0.3.0 Production
       RETVAL=`sqlplus -s FCSDWH_STG/${DBSTG}@${DBSRC} <<EOF
            EXEC FCSDWH_STG.FCA_HASH_TOTALS_PKG.HASH_TOTALS_COMPUTE(${PROVIDER},${UNINUM},${EXTRACT_DT},${VER_NUM});
            EOF`
            if [ `echo ${RETVAL} | egrep "ERROR"` ]
            then
                    logit "Error While Generating The SQLPLUS Output File, Please Check"
                    exit 1
            else
                    logit "SQLPLUS Output File Has Been Generated Successfully"
            fiThanks much.

    Ariean wrote:
    I am testing the same above functionality with the below sample procedure, and I am purposefully making it compile erroneous with "dbms_output.put_lin" just for sake of testing.
    create or replace
    procedure today_is as
    begin
    dbms_output.put_lin('Today is : ' || to_char(sysdate,'DL'));
    end today_is;This is sample shell script "test.sh" I am using
    #!/bin/bash
    RETVAL=`sqlplus -s FCSDWH_STG/FCSDWH_STG@dwdev <<EOF
    set termout off
    exec today_is;
    EOF`
    echo "start here"
    echo ${RETVAL}
    echo "end here"
    if [ `echo "$RETVAL" | grep "ERROR"` ]
    then
    echo "Error While Generating The SQLPLUS Output File, Please Check"
    exit 1
    else
    echo "SQLPLUS Output File Has Been Generated Successfully"
    fiBelow is my output
    start here
    BEGIN today_is; END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00905: object FCSDWH_STG.TODAY_IS is invalid
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    end here
    /home/infrmtca/bin/test.sh: line 8: [: too many arguments
    SQLPLUS Output File Has Been Generated SuccessfullyI don't understand why it is printing "SQLPLUS Output File Has Been Generated Successfully" though it errored out.Because statements within backquotes are executed before the statement calling the backquote. The [ command has too many arguments coming from the echo and grep.  You might put just that test part of the script in it's own little script and test it, it seems to say that whether there is an ERROR in $RETVAL or not.  You might need to man test and see if you need a -z argument or something.
    >
    Edited by: Ariean on May 15, 2013 10:08 AM
    Edited by: Ariean on May 15, 2013 10:16 AM

Maybe you are looking for

  • Can I use my monitor with a Mac Mini?

    I have this monitor from Dell, 19". http://accessories.euro.dell.com/sna/productdetail.aspx?c=it&l=it&s=dhs&cs=itdhs 1&sku=53808 Can I use MacMini with this monitor without problems? Problems like slow refresh or other problems.. I answer this becaus

  • ISE 1.2 notifications

    Dears ,           is there anyway to send notifications about authentication failures to be sent by mail?

  • How do you verify the completeness of a restoration drill?

    One responsibility of the DBA is to ensure the database backups are usable. Running the restore / recover commands in rman is easy. However, how would you verify the correctness of the restoration? Or do you believe that when rman says it's Ok and or

  • Why is mercury playback engine greyed out on the r9 290

    hey everyone so i just got the r9 290 and i thought CC was meant to enable open cl but the mercury playback is greyed out

  • File sizes displayed in Bytes?....

    Since upgrading to Lion, when I try getting info on a folder/file, the size used on the disk or filesize is displayed in Bytes (with GB's in parantheses afterwards). This seems unintuitive to me and makes it a little less easily apparent what the fil