Running java in linux script

Suppose to package all necessary *.class in example.jar in following way,
bin.start.class
business.bus.class
and the class file that contain main is bin.start.class.
There is no problem to run following under linux shell prompt. java VM is under PATH searching path. i.e.
$java -classpath example.jar bin.start
However, there is some problem to run a script which contains 'java -classpath example.jar bin.start' under linux shell prompt.
May I have any clue to identify this problem?
Thanks in advance.

For case 1: Does any case work? When I see "[un]able to locate the main method" then I think that that the class was found but that the main method is not declared properly.
Of course, main must be declared with exactly these keywords:
static public void main( String arg[]) {
...For case 2: you still have some kind of classpath problem.
If your script really has the line
java -classpath example.jar bin.start
then I still think your current working directory at the time that this line is run not that same directory as where the jar file is.
If you have JAVA_HOME defined, you might want to try:
pwd
$JAVA_HOME/bin/java -classpath example.jar bin.start
Another suggestion: If your $PATH variable is long, try to shorten it to a short list of directories. You can test with just /bin:/usr/bin .
Also, is your shell Bash or C-shell? Is your script Bourne shell (/bin/sh) or Bourne?

Similar Messages

  • ..running java in linux!!!

    hai java-landers,
    i actually want to see java running in "linux" system...
    the procedure, they've given in linux manual is very lenghthy
    and tedious....
    could any of u give me a good procedure for that....
    (actually i don't know where my message should go to which category...
    so, i pasted here...
    hope..u won't fire me next time!!!!)

    Download the linux self-extracting file (not RPM).
    If you are going to install as root, then log in as root now. You will need to be root if you want to install in any directory outside of your home directory -- such as a system directory (/usr/local in the example below).
    Move to the directory where you wish to install Java:
    $ cd /usr/local
    Make sure the file is set to "executable":
    $ chmod +x /home/waldo/j2sdk-1_4_1_02-linux-i586.bin
    Execute the file:
    $ /home/waldo/j2sdk-1_4_1_02-linux-i586.bin
    Now log out of root. You're done.
    Test your installation by typing something like:
    $ /usr/local/j2sdk-1.4.1_02/bin/java -version
    If you want to run java without typing the full path, you must put Java's bin directory in your path:
    $ echo path
    $ export PATH=$PATH:/usr/local/j2sdk-1.4.1_02/bin
    $ echo path
    (the "echo path" is not necessary; it's so that you can see what's going on)
    Now you should be able to type:
    $ java -version
    You will need to put the "export PATH=..." line in your .bash_profile script file for it to be permanent.

  • Running java in Bash script

    Hi all,
    I need to run a bash script in Linux which will then run a java program. I managed to run the script successfully (and running the java program eventually) by doing ./myScript. However, when my script is being called by some other programs, the java program doesn't run. I've check the classpath and path, seems everything is in place. I tried having this :
    java myjavaProg
    in myScript, it doesn't work.
    I also tried this, it doesn't work as well :
    java -classpath /usr/local/nagios/libexec myjavaProg
    Anyone has any idea why? Thanks in advance.

    I'd suggest editing your bash script, replacing the java call with one that invokes a class with a clearer sense of what it's doing. I mean, write a small class that creates a file in /tmp or something, so you can be more sure whether or not it's being invoked.
    Perhaps your java program is running, but it's behaving differently in these circumstances.

  • Running Java program from script shell using SSH

    Hello!
    I have this problem: I need to run a java command like: java Prog arg1 arg2 arg3 on i machines, using a shell script.
    First of all, I'm trying to make it work for a single machine. But the problem is when I write the line << ssh user@localhost "java -classpath /a/b/ Prog arg1 arg2 arg3" >> and run the script, it is not able to execute the entire line. Is there a special options for the arguments of my Prog class? I want to mention that between my arguments there is another text file which is read by the Prog and when i run the script says it cannot find that file; Please any ideas for not remain stuck here?
    Thank You in advance!

    Hello! Thank you for being so helpful..
    The part with << is not existent in my script, I've put it just here for quotation.Sorry
    So, from the terminal under Linux I run the command like this: I go to my folder where I have all my .java Classes and I execute the command java Prog arg1 arg2 arg3 . Where arg1...arg3 are arguments which are read from the terminal and then used in my Prog. One of the arguments is a text file, from which Prog.java reads line by line it's content. How can I run the same thing , under a script using SSH? This is basically my question, taking into consideration what I've written in my first post.

  • Pls help (running java on linux)

    Hello freinds,,
    I am in deep need..can anyone pls help me...
    I want to run my java programs on linux server.. Below are the steps I went thru to install jdk
    *** Download and copy j2sdk-1_3_1_10-linux-i586.rpm.bin to /usr/local/src.
    % su -
    # cd /usr/local/src
    # chmod +x j2sdk-1_3_1_10-linux-i586.rpm.bin
    # ./j2sdk-1_3_1_10-linux-i586.rpm.bin
    # rpm -ivh j2sdk-1_3_1_10-linux-i586.rpm
    Now test Java:
    # /usr/java/jdk1.3.1_10/bin/java -version
    Set the PATH environent variable.
    PATH="$PATH:/usr/java/jdk1.3.1_10/bin:."
    export PATH
    I went thru all above commands uninterruptedly.. Then I copied the folder containing programs in jdk1.3.1_10/bin folder
    Now when I am trying to complile or run an existing class it's gving following error message :
    java: command not found
    OR
    javac: command not found
    Can any one pls tell me where I am going wrong???
    Thanks in advance..

    From your query i understand you've installed java at "/usr/java/jdk1.3.1_10" location on your Linux box. I've a couple of queries -
    when u try to run "/usr/java/jdk1.3.1_10/bin/java -version" what do u see. Do u see the Java version information displayed on your screen ?
    and when you try export -ing the PATH variable with the following location added "/usr/java/jdk1.3.1_10/bin" and in the same shell type "which java" what do you see ? You should be seeing "/usr/java/jdk1.3.1_10/bin/java"
    If the above works then make changes to your profile file in order to ensure changes are saved for subsequent sessions.

  • Running Java on Linux

    Hello everyone,
    I am familiar with programming in Java on the Windows environment.
    However, I have recently installed Mandrake 10 on my desktop, and downloaded Sun's J2SDK 1.4.2_05 for Linux GTK2 systems.
    I have setup the environment variables for JAVA_HOME and CLASSPATH, and everything seems to be in order (I manage to call java and javac from the command line). The problem is that, whenever I try to run a java program, I get the following message:
    "Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object"
    How may I solve this?
    Thanks in advance for the help

    What did you set CLASSPATH to? Until you understand how Java's "package" construct works and how classes are found it's best not to set it, it often causes more problems than it solves.
    It sounds like you have got a very old version of java installed and it is getting used instead of your newly installed 1.4.2. I know that some Redhat distributions have this problem but I'm not sure about Mandrake 10. What is the output of "java -version" ?

  • Runtime exec to run linux scripts

    Hi,
    I have been having trouble running a simple linux script from within my java program. So far, this is the command line i am passing to the exec() method:
    String[] commandArray = {"/bin/sh", "-c", "sh",
    "/home/charles/java/ideaProjects/Condor/linuxScripts/LinuxSubmit.sh",
    "TwoMinTest.cmd"};
    Process proc = rt.exec(commandArray);
    The last paramater, "TwoMinTest.cmd" is a varibale that is passed to the script. The command works fine from a linux terminal window but from the java program the process just hangs with no out put from the script (the script does an echo "hello" first). Both the error and input streams obtained from the process do not output anything. If i instert a deliberate mistake into the command the error stream outputs it fine. Any idea why it hangs?
    thanks, Charles

    I've fixed it for anyone who's interested, this is what i did:
    String[] commandArray = {"/bin/sh", "-c", "sh"};
    Process proc = rt.exec(commandArray);
    OutputStream out = proc.getOutputStream();
    PrintWriter p = new PrintWriter(out);
    p.println("sh /home/charles/java/ideaProjects/Condor/linuxScripts/LinuxSubmit.sh " +
    "TwoMinTest.cmd");
    p.flush();
    and it flew like a bird.
    charles

  • Run java as a different process name in Linux

    I have multiple java applications running on a linux platform. When I look at the process list, they all say java. I want them to have a unique process name. The closest I have gotten is starting the java app in a script, and that script name shows up as well as the java app. This could be all fine and dandy, but if someone kills the script, the java process continues on. It would be nice if I could say run this process as this name in Linux, but I know of no such thing. I asked this on LinuxQuestions.org and got a response to use Launch4J...which creates executables for Windows...so that wasn't very helpful. I was hoping the Java community might have a little more insight.

    rename the java binaryOr instead of renaming, you could do a symlink... I
    don't have a machine to test on, but I think creating
    a symlink to the java executable and running that
    symlink would change the executable's name in the
    process table.nah, the process would still be called 'java'

  • Run Linux script with Runtime.exec

    Hi there!
    I want to run some Linux script files out of a Java application.
    I'm currently using a code like this:
    Runtime rt = Runtime.getRuntime();
    Process p=rt.exec("//home//scriptFile1");But this isn't working. Although I'm getting no exeption, the file isn't executed.
    It looks like he's doing something, but he's definitly not processing the file.
    I think the problem is probably, that in scriptFile1, I call some other script files (which call itself some other script files).
    E.g. like this:
    scriptFile1:
    scriptFile2
    binary1
    binary2
    scriptFile3Any ideas?
    Thank you!

    Hi! I now get at least some error messages, when I call the script file:
    knoppix@Knoppix:~/Desktop$ java Main
    start
    ERROR>/media/hda5/scripts/startds_2: line 1: stop: command not found
    ERROR>/media/hda5/scripts/startds_2: line 3: dspp_2: command not found
    ERROR>/media/hda5/scripts/startds_2: line 5: killcan: command not found
    ERROR>/media/hda5/scripts/startds_2: line 7: canpdemsimeit: command not found
    ERROR>/media/hda5/scripts/startds_2: line 9: demsimeit: command not found
    ERROR>/media/hda5/scripts/startds_2: line 11: guidemsimeit: command not found
    ERROR>/media/hda5/scripts/startds_2: line 13: MCAbrowser: command not found
    ExitValue: 0These "lost" commands are all located in the same directory as the script I call, so I wonder why.
    I could adjust every command by adding in front of it the absolute path in the script file. That would work. But maybe I can pass in some other way the directory, in which he should search for the commands. That would save me a lot of work...
    I will RTFM but if anyone has currently an idea: please post...
    THX

  • Java script and the new and not improved firefox don't work. Please let me be able to run Java again.

    I use SAP Infoview for work. To modify reports it requires a Java script to run. I had it set up in the previous version of ff to always allow from this specific site and it worked wonderfully. Now, in the new version, despite following all of the instructions from others, I cannot do my work because I cannot run Java script. I can still run it in Safari, but Safari is a last resort for me to use. I prefer Firefox and have all of my links stored there.

    Some sites are not fully compatible with Firefox 4's new HTML5 rendering engine. Can you turn that off and test without it? Here are the steps:
    (1) Open a new tab, then type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the filter box, type or paste '''html5''' and pause while the list is filtered
    (3) Double-click '''html5.parser.enable''' to toggle it to false (it should turn bold).
    Then change back to the SAP tab and reload the page.
    Does that make any difference?

  • 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 run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • Non secure running Java Script! Как с этим бороться?

    браузер не показывает некоторые страницы и пишет: Non secure running Java Script! Как с этим бороться?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Someone is using faebook to run java script to get data and email from me in windows 8

    someone is using faebook to run java script  to get  data  and  email  from  me in  windows  8

    Is this a developer question?
    Jeff Sanders (MSFT)
    @jsandersrocks - Windows Store Developer Solutions
    @WSDevSol
    Getting Started With Windows Azure Mobile Services development?
    Click here
    Getting Started With Windows Phone or Store app development?
    Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

  • How to run Java program as Daemon Server in linux

    How to run Java program as Daemon Server in linux
    i would like to run the java program on system start up in a redhat linux system
    can any one provide rc.status file

    http://wrapper.tanukisoftware.org/

Maybe you are looking for

  • Send word or pdf document as HTML email

    Hello all, we have word documents (on a local file) that we want to send via SAP as HTML email, i.e. we need the content of the word document in the email body. The documents also contain images. With the class cl_bcs I can send mails including attac

  • Best Practise for loading data into BW CSV vs XML ?

    Hi Everyone, I would like to get some of your thoughts on what file format would be best or most efficient to push data into BW. CSV or XML ? Also what are the advantages / Disadvantages? Appreciate your thoughts.

  • Lens Correction in Aperature 3

    I just upgraded to a full frame camera (Nikon D600). I understand that Aperature 3 cannot perform lens corrections (e.g., barrel distoration). Anyone have a recommendation on a good plug in that gives good results and is easy to use? Thanks in advanc

  • I have nokia 5130 xpress music.Why I can't install firefox in my phone.

    I have nokia 5130 xpress music.Why I can't install firefox in my phone.

  • Partial Page Rendering - newbie question

    I am a newbie to ADF and I am in the process of trying out the tutorial "Developing Ajax-Based User Interfaces with ADF Faces Rich Client Components" http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_56/jdtut_11r2_56.html I have a question reg