Calling one java program (with main method) 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!");
}
Stop posting here. The crosspost remark was to alert others that there is a duplicate topic - all answers should be centralized in one so as to not waste people's time duplicating answers when they don't see both topics and the answers therein.
Similar Messages
-
How to call a dialog program with return value in another dialog program
Dear All,
How can I call a dialog program with return value from another dialog program?
Regards,
Alok.Hi Alok,
You can you SET/GET parameters to do this.
This is some information about this.
To fill the input fields of a called transaction with data from the calling program, you can use the SPA/GPA technique. SPA/GPA parameters are values that the system stores in the global, user-specific SAP memory. SAP memory allows you to pass values between programs. A user can access the values stored in the SAP memory during one terminal session for all parallel sessions. Each SPA/GPA parameter is identified by a 20-character code. You can maintain them in the Repository Browser in the ABAP Workbench. The values in SPA/GPA parameters are user-specific.
ABAP programs can access the parameters using the SET PARAMETER and GET PARAMETERstatements.
To fill one, use:
SET PARAMETER ID pid FIELD f.
This statement saves the contents of field f under the ID pid in the SAP memory. The ID pid can be up to 20 characters long. If there was already a value stored under pid, this statement overwrites it. If you double-click pid in the ABAP Editor, parameters that do not exist can be created as a Repository object.
To read an SPA/GPA parameter, use:
GET PARAMETER ID pid FIELD f.
This statement places the value stored under the pid ID into the variable f. If the system does not find any value for pid in the SAP memory, sy-subrc is set to 4. Otherwise, it sets the value to 0.
Thanks,
SriRatna -
Running a main Method from another class??
Hi,
I am trying to run a main method from another class, eg the main method is in Class1 and i am trying to run it from class2.
So I have
class1 c1 = new class1();
c1.main();and I get the following compilation error:
clas2.java:42: main(java.lang.String[]) in class1 cannot be applied to () c1.main();
any ideas on how to do this correctly
thanks in advance,
DonalHi thanks for the replies,
tried just passing a string earlier and that just gave errors too, I should have been more specific and pass a string array.
Its working now thanks again.
Donal -
I need to call a java program and pass parameters from C#
I'm new to C# and was given a project to rewrite some of my old VB.net programs to C# to help me learn. These VB programs call quite a few .bat files that have calls to java programs in them. I'm doing okay converting my VB code, but I've been
stumped for days trying to figure out how to call java from C#.
Does anyone here know how to do this? I really should've had this figured out by now and my back is to the wall. Ugh :(
This is the line from the .bat file that I need to convert to C#.
call jvbat production_r115.Automotive m:\data\MK115mn.100 m:\data\MK115mn.101 %6
There is one parameters being passed, %6
I would be forever grateful if someone can show me how to do this!Hi Joni,
Do you mean call a bat file that it is a Java program from C#? If so, there is an article talking about it.
If that's not what you're trying to do, please be more specific about what you're trying to do.
http://www.c-sharpcorner.com/UploadFile/maheswararao/CallingJavaProgramfromCS12062005233321PM/CallingJavaProgramfromCS.aspx
Now the next issue is pass some parameters from C#.
The above article tells using Process.Start() method to call java program. Also in this class, you could specify them all in the
Arguments property:
var p = new Process();
p.StartInfo.Arguments = string.Format("{0} {1}", argument1, argument2);
For more detailed information, please refer to
C# Passing Multiple Arguments to BAT File
Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control
these sites and has not tested any software or information found on these sites;
Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information
found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
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. -
Java programming language main method question?
Hello everyone I am quite new to the Java programming language and I have a question here concerning my main method. As you can see I am calling 4 others methods with my main method. What does the null mean after I call the method? I really don't understand is significance, what else could go there besides null?
public static void main(String[] args)
int cansPerPack = 6;
System.out.println(cansPerPack);
int cansPerCrate = 4* cansPerPack;
System.out.println(cansPerCrate);
have_fun(null);
user_input(null);
more_java(null);
string_work(null);
}Edited by: phantomswordsmen on Jul 25, 2010 4:29 PMphantomswordsmen wrote:
..As you can see I am calling 4 others methods with my main method. 'Your' main method? Your questions indicate that you did not write the code, who did?
..What does the null mean after I call the method?.. 'null' is being passed as an argument to the method, so there is no 'after the method' about it.
..I really don't understand is significance, what else could go there besides null? That would depend on the method signatures that are not shown in the code snippet posted. This is one of many reasons that I recommend people to post an SSCCE *(<- link).*
BTW - method names like have_fun() do not follow the common nomenclature, and are not good code for a newbie to study. The code should be put to the pointy end of your sword. -
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
RashmiHi 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 -
Invoking main method from cmd line (deployed as web app)
I have a application deployed as a web application (war file).
I want to create a regular java class with main method so that main can invoked
on a command line.
The main method wishes to share resources (DB connection pool etc) with the rest
of the web application.
Is it possible ? and how to invoke the main method inside the war(not jar) ?Hi,
if you deployed this to OC4J, open EM
http://server:port/em
and get to the Web service. You can execute it from here to see if generally this is working, or if you have a proxy problem only
Frank -
How do you call a java class from the main method in another class?
Hi all,
How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
Thanks
SI
Edited by: okun on May 16, 2010 8:40 PM
Edited by: okun on May 16, 2010 8:41 PM
Edited by: okun on May 16, 2010 8:47 PMgeorgemc wrote:
To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern. -
Can I call an object with synchronized methods from an EJB
I have a need for multiple threads (e.g. Message Driven Beans) to access a shared object, lets say a singleton, I'm aware of the "you can't have a singleton in the EJB world" issues) for read/write operations, so the operations will need to be synchronised.
I've seen various statements such as you can't use read/write static fields in EJBs and you can't use synchronisation primitives in EJBs but I've also seen statements that say its okay to access utility classes such as Vector (which has synchronised methods) from an EJB.
Does anyone know if there is a definitive answer on this? What are the implications of accessing a shared object with synchronised methods from multiple EJBs? Is it just that the EJB's thread may block which limits the ability of the container to manage the EJBs? In the Vector example above (from Professional Java Server Programming) did they mean its okay to use these utility classes provided they aren't shared across threads?
If I can't use a plain old Java Object does anyone know if there are other potential solutions for sharing objects across EJBs?
In my problem, I have an operation that I want to run in a multi-threaded way. Each thread will add information to the shared object, and this info may be used by the other threads. There's no lengthy blocking as such other than the fact that only one thread can be adding/reading information from the shared object at a time.
I've trawled through this forum looking for similar questions of which there seem to be many, but there doesn't seem to be any definitive answers (sorry if there was and I missed it).
Thanks
MartinYou can share objects among EJB's or among objects used by one or more EJB's. You can use synchronization primitives - nothing will prevent you from doing that.
After all, the container classes, JVM-provides classes, JDBC, JCA, JNDI and other such classes do all of this with impunity. You can too. You can use file and socket I/O as well, presuming you configure the security profile to allow it. Should you? Well it depends on what you need to accomplish and if there is another practical alternative.
Yes the specification warns you not to, but you cannot be responsible for the interior hidden implementation of classes provided to you by the JVM or third parties so you can never truly know if your are breaking these written rules.
But when you do these things, you are taking over some part of the role of the container. For short running methods that only block while another thread is using the method or code block and no I/O or use of other potentially blocking operations are contained in the method/block, you will be fine. If you don't watch out and create deadlocks, you will harm the container and its managed thread pool.
You should not define EJB methods as synchronized.
Also, if you share objects between EJB's, you need to realize that the container is free to isolate pools of your EJB in separate classloaders or JVM's. It's behavior can be influenced by your packaging choices (use of .ear, multiple separate .jar's, etc.) and the configuration of the server esp. use of clustering. This will cause duplicate sets of shared classes - so singletons will not necessarily be singleton across the entire server/cluster, but no single EJB instance will see more than one of them. You design needs to be tolerant of that fact in order to work correctly.
This isn't the definitive answer you asked for - I'll leave that to the language/spec lawyers out there. But in my experience I have run across a number of occasions where I had to go outside of the written rules and ave yet to be burned for it.
Chuck -
Calling a java program from a perl CGI
The perl program takes form data, does stuff with it, writes it to a file, and then calls a java program to encrypt it, and email it.
When I telnet to the server, I can run the java program using:
java CryptoMail.class [email protected] data.txt
The java program uses jar files which are defined in the Classpath in an .sh script in the etc/profile.d/ directory.
When I run the perl cgi from the web, it doesn't work. I figured that it wasn't getting the classpath defined because the user wasn't actually logging in so I tried it with java -classpath etc...
Any ideas???
I tried the following:
==================
$cmdtorun='/usr/j2sdk1.4.0_02/bin/java CryptoMail $email $file';
system($cmdtorun);
==================
and also tried variations of the following:
==================
/usr/j2sdk1.4.0_02/bin/java -classpath .:/home/sites/site1/web/cgi-bin/activation.jar:/home/sites/site1/web/cgi-bin/mail.jar /home/sites/site1/web/cgi-bin/CryptoMail [email protected] /home/sites/site1/web/cgi-bin/wellsfargo.txt
==================>
Any ideas???Write a script file that explicitly paths everything.
Test it by setting the class path and path to nothing in the environment and seeing if it works.
Redirect errors from everything to a log file.
Then run the script from your perl program. Verify that it did not return any errors. Verify there are no errors in the log file. -
Calling one report program from another
Hi All,
i am calling one report program from my program & exporting it's output to SAP-SPOOL using SUBMIT statement. I want to fetch the spool no in my program for this spool. Please guide me how this can be achieved? i have tried SYST- SPONO but it's not working.
Thanks & Regards,
Chetan.Hi,
Initially check this it might be helpful to u.
http://help.sap.com/saphelp_sm40/helpdata/en/30/cc154219fce12ce10000000a1550b0/content.htm.
Even use the function module slike Job_open , Job_close this is also one of the methid to achive spool requests.
Regards,
Sana.
Reward with points if found helpful.. -
Problems running bat file with calls to java programs (.jar)
I created a bat file with calls to jar programs. In each line,
I put a call to the programs with parameters, but bat only
executes the first line and ends execution.
All lines of my bat file must be executed.
What should I do?
Best Regards,
Pedro Felipe
[http://pedrofao.blogspot.com|http://pedrofao.blogspot.com]
[http://viajantesmundo.blogspot.com/|http://viajantesmundo.blogspot.com/]user8730639 wrote:
I realized that the problem isn`t my bat file. I made tests calling another jar files and then all the lines of the batch file were executed. So, the jar file called on my previous bat is finnishing the execution. I verified and the jar apps worked without error.
I would like to know if exists any command in Java that can cause this effect (close a batch), to modify the open source code of the application.Not that I know of.
Is prism a bat file?
If you are invoking bat files from your bat file without using call that would explain it
:: mymain.bat file
:: call the first bat file
call prism.bat arg1 arg2 arg3
:: call the other bat file
call prism.bat arg4 arg5 arg6
:: -
Requesting an overview of how to call a Java program from EBS.
Hi,
I am an experienced Java developer in the middle of an implementation of EBS 12g. I am very new to EBS and I'm not sure where to start on this. I need to provide users the ability to call a Java program that prints a report from EBS. I would be grateful if somebody would outline the general approach that should be used. Links to documentation/tutorials are appreciated also.
Thanks,
MikeHi,
I need to provide users the ability to call a Java program that prints a report from EBS. Are you referring to Java concurrent programs? If yes, please see the documents referenced in this thread.
Java Concurrent Programs
Java Concurrent Programs
Regards,
Hussein -
CALL A JAVA PROGRAM FROM ABAP -- NEED HELP
Hi all,
Can somebody tell me how to call a java xml code from an ABAP program? First let me know if at all, is it possible to call a java program from SAP that is from an ABAP executable progam?
Please suggest me in this. All your inputs in this is valuable to me and highly appreciated.
Thanks in advance,
Vaishnavi VaradarajanHi,
Previous explanation i gave is not correct.
ABAP web services expose the function modules outside R/3, so that other technologies like Java can consume that webservice and read the data in R/3 using the function module.
For your requirement, create a Java web service to read the XML. Consume this webservice in ABAP. This way you can read the XML from ABAP.
Regards
Srikanth KV.
Maybe you are looking for
-
does anyone know that thay charge $3 every time you pay cash that is a rip off i started with a cell phone 20 years ago and it was 19.99 but know thw bill is almost 200 dallors when does it stop with corprate greed?????? anyone have a opion????
-
FaceTime fails to connect to active wi fi on my iPad?
FaceTime fails to connect to active and working wi fi on iPad? Help!
-
Where can i download 12.1
Hi All, I need to download documaker studio 12.1 but i only see 12.3 on oracle portal. Where have other versions gone? Thanks
-
Hi experts.. i am new to BSP Application. Please any body guide me to terminate BPS page generation conditionally. actually in BSP application i used abap coding to validate a field based on condition. my requirement is if field satisfy with conditi
-
Verifying DNS Record Readiness fails before domain rename
I'm in the process of a domain rename. I am verifying DNS readiness (see: http://technet.microsoft.com/en-us/library/cc816721(v=ws.10).aspx)When I run the command: Dcdiag /test:DNS /DnsRecordRegistration /s:<my domaincontroller>I get the following er