Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Pass String as params from one Java App to another

mKorbelMay 28 2011 — edited May 28 2011
I'm trying to pass String as parameter from one Java Aplications to second as StartUp parameter

for example I have Aplications that must call start another Java Aplication (just contains only JOptionPane, JDialog or simple JFrame) before System.exit(0);, there I trying to send some descriptions from closing application to another,

these code is simulations what I tried that and in this form, code works correctly and displayed String into the JTextArea ...
import java.io.IOException;
    import java.util.concurrent.*;

    public class TestScheduler {

        public static void main(String[] args) throws InterruptedException {
            ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
            executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
            executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
            for (int i = 0; i < 10; i++) {
                final int j = i;
                System.out.println("assign : " + i);
                ScheduledFuture<?> future = executor.schedule(new Runnable() {

                    @Override
                    public void run() {
                        System.out.println("run : " + j);
                    }
                }, 2, TimeUnit.SECONDS);
            }
            System.out.println("executor.shutdown() ....");
            executor.shutdown();
            executor.awaitTermination(10, TimeUnit.SECONDS);
            try {
                Process p = Runtime.getRuntime().exec("cmd /c start java -jar C:\\Dialog.jar 'Passed info'");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            System.out.println("System.exit(0) .....");
            System.exit(0);
        }

        private TestScheduler() {
        }
    }

//
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;

public class Main {

    private static ArrayList<String> list = new ArrayList<String>();

    public Main() {
        JFrame frm = new JFrame();
        JTextArea text = new JTextArea();
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); ++i) {
                text.append(list.get(i));
            }
        }
        JScrollPane scroll = new JScrollPane(text,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.add(scroll, BorderLayout.CENTER);
        frm.setLocation(150, 100);
        frm.setSize(new Dimension(400, 300));
        frm.setVisible(true);
    }

    public static void main(String[] args) {
        if (args.length > 0) {
            for (String s : args) {
                list.add(s);
                System.out.print(s + " ");
            }
        }
        Main m = new Main();
    }
} 
my question :

if is there exist another way how to pass some value from one Java Aplication (there must be called System.exit(0);) to another Java Aplication, another way as I tried by using Process/ProcessBuilder

my crospost http://stackoverflow.com/questions/6121990/pass-string-as-params-from-one-java-app-to-another
This post has been answered by 796440 on May 28 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2011
Added on May 28 2011
2 comments
695 views