Trouble in Unix calling a Java utility from another shell script

Hi,
I'm able to run a shell script (call it script B) in Unix which calls a Java utility. When I call script B from another script (script A) I get the error below. I have done much work to make sure the environment variables are the same.
java.util.zip.ZipException: error in opening zip f
ile
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:69)
at com.something.runtime.ZipFileApplicationSource.<init>(ZipFileApplicationSource.java:22)
at com.something.runtime.ZipFileRuntime.main(ZipFileRuntime.java:35
ANY HELP WOULD BE GREATLY APPRECIATED.
Thanks

Here's my guess, if this doesn't work, post your scripts and maybe that will help.
When you run your script B, you said it works. I think the problem is that when you run script B, your shell and envirenment variables are set by the window you're working in. When you call script B from script A, it creates a new shell to run it and it doesn't run the files that are run when you start a terminal or a telnet(it won't run .cshrc, .kshrc or .login). Depending on what OS you're using, I think the default shell is sh for most of them. The first line of script B should be
#!/(your bin directory)/(shell you're using)
for me it's
#!/bin/tcsh
then you might want to run your startup file to set envirenment variables, paths, etc...
source (your user directory)/(the file name)
for me it's
source ~/.cshrc
Then if you need to set the environment variables in your script.
set CLASSPATH /usr/local/j2ee/bin.....
set PATH /bin:/xyz....
If that doesn't help post your scripts, or if I didn't explain it will enough, just ask.

Similar Messages

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How to call a C function calling a Java Method from another C function ?

    Hi everyone,
    I'm just starting to learn JNI and my problem is that I don't know if it is possible to call a C function calling a Java Method (or doing anything else with JNI) from another C function.
    In fact, after receiving datas in a socket made by a C function, I would like to create a class instance (and I don't know how to do it too ; ) ) and init this instance with the strings I received in the socket.
    Is all that possible ?
    Thank you very much for your help !

    Hard to understand the question, but by most interpretations the answer is going to be yes.
    You do of course understand that JNI is the "API" that sits between Java and C and that every call between the two must go through that. You can't call it directly.

  • Calling one java program from another

    Hello,
    How can I start another java program from one? Lets
    say I want Second.java to start by calling it from
    First.java. How do I do it? The two programs are given
    below. Any help is appreciated.
    Thanks,
    Amanda
    First.java
    import java.io.*;
    import java.lang.reflect.*;
    public class  First
         public static void main(String[] args)
              Process theProcess=null;
              System.out.println("Hello World from First.java!");
              String second=new String("Second.java");
              //System.load(second);
              //Runtime.getRuntime().load(second);
              try
                   theProcess=Runtime.getRuntime().exec( "Second.java"
                   System.out.println("after exec");
              catch (IOException ioe)
                   System.out.println(">>IOException thrown in
    First.java while calling
    Second.java."+ioe.getMessage());
    Second.java
    public class  Second
         public static void main(String[] args)
              System.out.println("Hello World from Second.java!");
    }

    Thanks, warnerja
    What if Second.java is on a remote machine i.e.
    First.java and second.java are on different machines?
    Will I have to use RMI?Well, you'd have to do some kind of remote invocation. Depends on what kinds of apps house the classes. There are all kinds of ways - web services, servlets, RMI, (maybe others...)
    That's a totally different question than what you originally posted, and would have been very relevant to say so in the first place.

  • Calling a java application from another

    Hello,
    i have noticed a strange behaviour of my java app when i open it from another java app. When i run the core application with a bat file using jre1.6 everything works fine. Now what i want to do is create an application that checks the existance of jre 1.6, downloads it if it does not exist and run real application with the new jre. The second small app runs with a small jre 1.4.2. In reality it seem to work fine, it downloads the jre1.6 folder and exits normally. However when the real application is launched it behaves strangely without throwing any exceptions. And this behaviour seems to be random. for example, a jpanel may not show any components, or the whole jframe may close suddenly. Does anyone have any idea what is going on? Is there a chance that some classes of the first jre remain in memory and conflict when the second application is launched?

    Just a wild guess: maybe you're invoking the java 1.6 binaries, but JAVA_HOME or something is pointing to java 1.4 libraries (or vice-versa), and you've found some weird interaction issue.

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • Invoking a java program from a shell script!

    Can this be done?
    Ive written a simple compiler for the language buru which just reads/parses and then executes a file for this java like language. But what Im wondering is if I can write a shell script something like this
    #!/bin/bash
    java Interpreter one.buru
    this isn't working so its not correct but if someone knows how to do so there are duke dollars going for it Cheers :)

    The most likely reason is that java is not finding your class.
    That is probably because when you execute the script the "working directory" is not in a location that works with your class path.
    You should be able to find the working directory and class path with the following commands (or some variation of them) added to the beginning of your script.
    cd
    echo $CLASSPATH

  • Calling a Java Program from another

    Hi,
    I am putting together a Java program which will launch other Java programs.
    I was thinking of doing this by calling unix scripts from my java program by getting an instance of the Runtime object and then calling the exec method with the script name.
    I am just wondering what is the best practice when doing this? i.e., dealing with timeout issues, and errors in the scripts etc.
    I have read this article, which is quite good: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
    Is there any code available on the web that deals with all of the basic error scenarios?
    Is it good practice to use a java program to call another java program? Or is there a better way of doing this?
    The main reason I am using java is because I am most familiar with it and I need to connect to a database as well and do some manipulation of results returned.
    Any thoughts or suggestions would be much appreciated.
    Message was edited by:
    LondonJavaDev

    Thanks Prometheuzz
    Is the main difference between your suggestion and
    using the Runtime.getRuntime().exec(cmd) way of doing
    things is that in the former both eill run as the
    same process (Thread) but in the second scenario the
    .getRuntime().exec(cmd) will start a separate new
    thread?
    Many ThanksCorrect. But you can create a sort of wrapper class for A which implements Runnable and stuff it in it's own thread. If you're dealing with Java code only, I advise you to create threads yourself instead of letting your OS handle them.
    Here's a demo:
    class Foo {
        public static void main(String[] args) {
            (new Thread(new ARunner())).start();
            B.main(null);
    class ARunner implements Runnable {
        public void run() {
            A.main(null);
    class A {
        public static void main(String[] args) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) { /* ... */ }
            System.out.println("A");
    class B {
        public static void main(String[] args) {
            System.out.println("B");
    }Of course, you can create a wrapper for B as well.

  • Calling a java webservice from another application say a Vb client

    Hi,
    I have written a simple web service which greets the user "Hello" and using Apache axis and deployed on Tomcat.Everything works fine.
    But lots being said about interoperability but right now i cannot appreciate that as i don't know how to call my webservice written in java to be called from say a VB application or a component running on IIS server.
    Can anyone write a small snippet of code to do that..
    Your help is highly appreciated...
    thanks
    vasubabu bathina

    Hi,
    Thanks for your reply but i am looking for something more.Like how to get the WSDL file from my webservice and writing a simple clinet application accessing the webservice written using Apache Soap.

  • How do I perform a call to shell script from another shell script

    In /jacorb/bin I have to compile some IDL files to java, but I do not know how:
    In the terminal window, I am able to run #sh compile.sh
    But in compile.sh there is another call to a an idl.sh and a ir.sh at the same line
    The error say that it can not find these two files.
    What to do...
    Br Morten Bo

    My compile.sh file looks like this:
    #!/bin/sh
    PATH=/usr/jdk/jdk1.5.0_07/bin:$path;
    # my path --> /JacORB/bin/ and /JacORB/lib
    idl.sh -ir -d ../src -i2jpackage mortens:com.nokia.m2m.orb.idl.egsmt egsmt.idl
    %RESOLVE_JACORB_HOME%
    JACORB_HOME=${RESOLVED_JACORB_HOME}
    @RESOLVE_JAVA_CMD@
    JAVA_CMD=${RESOLVED_JAVA_CMD}
    exec "$JAVA_CMD" \
    @JACORB_BOOTCLASSPATH@ \
    -Djacorb.home="${JACORB_HOME}" \
    -Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB \
    -Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton \
    -classpath "${CLASSPATH}" \
    "$@"
    And my idl.sh looks like this:
    #!/bin/sh
    # @DONT_EDIT@
    @RESOLVE_JACORB_HOME@
    JACORB_HOME=${RESOLVED_JACORB_HOME}
    @JAVA_CMD@ -classpath ${JACORB_HOME}/lib/idl.jar:${JACORB_HOME}/lib/logkit-1.2.jar:${CLASSPATH} org.jacorb.idl.parser "$@"
    So, what d I have to put in instead of these @@ and $$
    I really do not know how to set up pathnames in solaris

  • Calling Java Application from another

    How can i call a Java Application from another java App.
    eg., If my Java application is called MyApp and i would like call another java application from within it.
    One way could be by using "System". I would like to know if there is any other method and is portable.
    Thanks in advance.

    hi,
    it works and not!
    if you start an other class with a command like this the 2nd prog/class terminates too if you terminate the caller-class!
    dear
    oliver scorp

  • Not able to execute one Java program from another one via. exec()

    Hi,
    I am new to this forum, so I might be asking a very trivial quetion.
    My program Ap1 is :
    class Ap1
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    p=rt.exec("javac,Pr.java");
    Runtime.getRuntime().exec("javac,Pr.java");
    When I run the above program, I get below error at the line 7(bold one):
    D:\batchwe>javac Ap1.java
    D:\batchwe>java Ap1
    Exception in thread "main" java.io.IOException: CreateProcess: javac,Pr.java err
    or=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at Ap1.main(Ap1.java:7)
    Path is set as below(which seems correct):
    D:\batchwe>path
    PATH=C:\Program Files\Java\jdk1.5.0_05\bin
    I am just wondering how to call one Java program from another one?!
    Please help.
    thanks
    Rashmi

    Hi diptaPB,
    Thanks for your suggestion.
    Here is how I tried it again, but not getting the desired output:
    Class Pr looks like below -->
    class Pr
    public static void main(String a[])
    System.out.println("hi from process");
    When I run 'Pr' from command prompt, i get the desired output:
    D:\batchwe>java Pr
    hi from process
    However, when I call 'Pr' from another program Ap2.java, it seems that it does not call 'Pr':
    class Ap2
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    String[] cmd=new String[2];
    cmd[0]="javac";
    cmd[1]="Pr.java";
    p=rt.exec("cmd");
    D:\batchwe>javac Ap2.java
    D:\batchwe>java Ap2
    ************* no output appears here***********************
    Looking forward for your help.
    regards
    Rashmi

  • Call a Java Application from MicroFocus COBOL (in UNIX environment)

    Hello,
    Could you please let me know, how to call a Java application from a MicroFocus COBOL application. If anyone has any code samples, that would be of great help.
    Thanks in advance,
    Tijo.

    You generally can't cause a program to be executed on a different >server. Basic security, you know. Besides this idea of having the Java >application run on a different server wasn't mentioned in your original >post. That leads me to believe we don't have the whole story.So I think you need to step back and find out what are the requirements. For example: Does your program need to start this Java application running, or is it already running and your program needs to connect to it somehow?
    My program has to start a Java class file, meaning that the Micro Focus COBOL module will call the Java class file. Will it be running on the same machine as your program, or on some other machine?
    For both cases, I would like to know the answer.a) Running on the same machine as my program is running.
    b) Running on the different machine.
    And then there are the questions about whether your program needs to have a conversation with the Java application, or whether it just needs to start it and that's all.
    COBOL program has to call a Java class by passing some parameters and Java class in turn process it and return some value back.. Kind of Request and Response model.Plenty of questions to be asked. Go and find out what they are.
    Sorry ... if I am not clear on my questions. Anyhow, thank you very much for providing the information.

  • Calling a Java Application from MicroFocus COBOL.... (in UNIX environment)

    Hello,
    Could you please let me know, how to call a Java application from a MicroFocus COBOL application. If anyone has any code samples, that would be of great help.
    Thanks in advance,
    Tijo.

    Annoyingly crossposted.
    http://forum.java.sun.com/thread.jspa?threadID=730657

  • Calling a Java Subpackage from a C program.... fails

    I am having alittle bit of trouble calling a java subpackage from my C program. I can call a package ok but not a subpackage.
    My directory path is c:\com\phoenix_systems_inc
    My CLASSPATH=.;c:\com;
    In the c:\com\phoenix_systems_inc directory is my FundsgClient.class
    The fundsgClient.java has a package declaration of
    package com.phoenix_systems_inc;
    within the fundsgClient.java is class:
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    ======================================
    in my C program I have
    options[0].optionString = "-Djava.class.path=c:\\com\\";
    cls = env->FindClass("/phoenix_systems_inc/com.phoenix_systems_inc.FundsgClient");
    I think that I am over declaring the path in FindClass.

    nope;; that is what I had initially;
    My CLASSPATH is CLASSPATH=.;c:\com;
    ==================================C program code
    memset (&vm_args, 0, sizeof(vm_args));
    vm_args.version=JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=c:\\com";
    vm_args.ignoreUnrecognized = TRUE;
    res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
    if (res < 0)
    fprintf(stderr, "Can't create Java VM\n");
         return 0;
    cls = env->FindClass("com/phoenix_systems_inc/FundsgClient");
    ===== is the java class code ==========
    package com.phoenix_systems_inc;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    import gnu.cajo.invoke.Remote;
    import gnu.cajo.utils.extra.Xfile;
    * Fundsg RMI Client
    * @author agesite
    * @version 1.0
    public class FundsgClient {
    static {
    PropertyConfigurator.configure("FundsLog.properties");
    // Log4j logger
         private static Logger log = Logger.getLogger("PhoenixClient");
    // Get RMI Server Hostname
    private static final String host = PhoenixClientProperties.getInstance().
    getProperty("PhoenixRMIServer");
    private static String port = "1198";
         * request
         * @param requestStr Request String
         * @return String Response String
         * @throws Exception
         public synchronized static String request (String requestStr) throws Exception {
              // Serialized object
              RequestObject requestObj = new RequestObject();
              requestObj.setRequest(requestStr);
              if (log.isDebugEnabled()) {
                   log.debug("Client Request: " + requestStr);
              System.out.println("//" + host + ":" + port + "/fundsgServer");
              Object object = Remote.getItem("//" + host + ":" + port + "/fundsgServer");
              String response = (String) Remote.invoke(object, "nativeFundsg", requestObj.getRequest());
              if (log.isDebugEnabled()) {
                   log.debug("Server Response: " + response);
              return response;
         * xferFile
         * @param sourceFile
         * @param destFile
         * @throws Exception
         public synchronized static void xferFile (String sourceFile, String destFile) throws Exception {
              try {           
                   Object xf = Remote.getItem("//" + host + ":" + port + "/xfileFunds");
                   // remoteInvoke = true means transfer can be performed from
    // server to client and vice versa
    Xfile.remoteInvoke = true;
                   Xfile.fetch(xf, sourceFile, destFile);
              } catch (Exception e) {
                   if (log.isDebugEnabled()) {
                        log.debug("Xfile.fetch exception: " + e);
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    }

Maybe you are looking for