Running one main class from another
Hey, i developed two main class. Each class produce it's one JFrame. One Frame suppose to at one point run the other frame when a start button is press. How should I go about doing it?
You can just call the other class's main method.
However, that's kind of messy. If you have any functionality in your main method other than just bootstrapping your program, it's probably better to refactor it out into a different method. Then your other class can invoke that new method.
Similar Messages
-
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 -
How sholud we call one jframe class from another jframe class
Hi
In my application i am calling one jframe class from another jframe clas.
how sholud we make previous jframe inactve when another jframe is invoked?(user sholud not able to make any changes on on parent jframe window when another jframe is invoked)
Pls reply.Sorry for me it is not possible to change existing code,
pls suggest me any other solution so that i can inactive parent jframe when child jframe execution is going on. -
How to call one Main MXML from another main MXML file and pass values between them?
Hi,
I am trying to populate a datagrid from a XML file ,which I have done successful
I am able to get data out of the datagrid on clicking on any element
Now when I click on any element in datagrid I want call a new mxml file which is also have Aplication tag and I want to pass that value of clicked element to it
This is the code I am using for getting data from XML into data grid in 1st MXML file and the XML file used.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="exp.send()">
<fx:Declarations>
<s:HTTPService id="exp" url="expLab1.xml" result="
resultHandlerQuestionBar(event)"/>
</fx:Declarations>
<s:Panel x="74" y="218" width="485" height="333" title="Work On Configured Experiments" id="p1" fontSize="14" chromeColor="#9BFDAB" dropShadowVisible="false" contentBackgroundColor="#E4EEE6" contentBackgroundAlpha="1.0" backgroundColor="#67B6AC" textAlign="left">
<mx:DataGrid x="35" y="33" width="338" height="88" dataProvider="{experimentdetails}" chromeColor="#FCFCFC" contentBackgroundColor="#FFFFFF" selectionColor="#FAFBFD" rollOverColor="#FCFDFF" focusColor="#FCFDFD" itemClick="onItemClick( event );">
<mx:columns>
<mx:DataGridColumn id="j1" dataField="experimentName" headerText="" itemRenderer="jaya">
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</s:Panel>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var workbenchname:ArrayCollection;
//private var a:String;
private function resultHandlerQuestionBar(event:ResultEvent):void
experimentdetails=event.result.List.experimentList.experiment;
[Bindable]
private var experimentdetails:ArrayCollection;
private var alert:Alert;
private var data:String;
private function onItemClick( e:ListEvent ):void {
data= experimentdetails.getItemAt(e.rowIndex).experimentName.toString();
alert=Alert.show(experimentdetails.getItemAt(e.rowIndex).experimentName.toString());
]]>
</fx:Script>
</s:Application>
and the xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<List>
<workbench>Basic Movement</workbench>
<experimentList>
<experiment>
<experimentName>Distance with varying time</experimentName>
<Rating>2</Rating>
<expNO>1</expNO>
</experiment>
<experiment>
<experimentName>Distance with Constant time</experimentName>
<Rating>1</Rating>
<expNO>2</expNO>
</experiment>
<experiment>
<experimentName>Time taken while decelerating</experimentName>
<Rating>3</Rating>
<expNO>3</expNO>
</experiment>
</experimentList>
</List>
Now the code for 2nd MXML is as follows
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="lable1" >
</s:Label>
</s:Application>Check out ExternalInterface class:
http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_2.html
If this post answers your question or helps, please mark it as such.
Greg Lafrance - Flex 2 and 3 ACE certified
www.ChikaraDev.com
Flex Training and Support Services -
Can you only run one main() in a jar?
Hi,
I was just wondering if you can only ever run one main() method from a .jar file? I have a project being developed in Eclipse, consisting of several packages and then several classes with main()s in each of the packages. When the whole project is packaged into one big jar then I can run one of the main() methods by specifying it in the manifest, but as far as I'm aware I can't access the others.
Is there some cunning way to call the main() method of a different class to that specified in the jar manifest, or do I have to compile every class as a separate jar? And if that's the case, is there really any advantage to putting the classes into a jar as opposed to just running from the .class files?
Any help much appreciated. :)
hWow, thanks for the quick responses guys!
You can execute the other main methods byexecuting:
java -cp the-class-path TheMainClassIsn't that just what I'd use from the compiled .class
files though?Correct, but you specify the jar on your classpath. e.g.
java -cp myjar.jar TheMainClasss1 or
java -cp myjar.jar TheMainClasss2
For example:
java -cp the-class-path my.class1
java -cp the-class-path my.class2
How does this relate to a single .jar file containing
both of those classes? See above
If I try those commands in the
directory containing the .jar file, I just get a
NoClassDefFoundError (they work fine in the directory
with the .class files though).That's because you didn't specify the classpath in the correct way.
Kaj -
How to kill one class from another class
I need to dipose one class from another class.
So that first i have to find what are all threads running in that class and then to kill them
Assist me.Subbu_Srinivasan wrote:
I am explaining you in clear way
No you haven't been.
>
In my application i am handling many JInternalFrame.Simultaneously i am running working on more than one frame.
Due to some poor performance of some thread in one JInternalFrame,the thread is keeps on running .
i could not able to proceed further on that screen.
So i have to kill that JInternalFrame.Yoinks.
To be begin with your problem sounds like you are doing everything in one thread. So stop doing that. Second when you get it split up and if a task is taking too much time then interrupt it. No kill. Interrupt. This means the worker thread needs to check sometimes if it has been interrupted. -
How to call inner class method in one java file from another java file?
hello guyz, i m tryin to access an inner class method defined in one class from another class... i m posting the code too wit error. plz help me out.
// test1.java
public class test1
public test1()
test t = new test();
public class test
test()
public int geti()
int i=10;
return i;
// test2.java
class test2
public static void main(String[] args)
test1 t1 = new test1();
System.out.println(t1.t.i);
i m getting error as
test2.java:7: cannot resolve symbol
symbol : variable t
location: class test1
System.out.println(t1.t.geti());
^There are various ways to define and use nested classes. Here is a common pattern. The inner class is private but implements an interface visible to the client. The enclosing class provides a factory method to create instances of the inner class.
interface I {
void method();
class Outer {
private String name;
public Outer(String name) {
this.name = name;
public I createInner() {
return new Inner();
private class Inner implements I {
public void method() {
System.out.format("Enclosing object's name is %s%n", name);
public class Demo {
public static void main(String[] args) {
Outer outer = new Outer("Otto");
I junior = outer.createInner();
junior.method();
} -
Accessing a variable defined in one class from another class..
Greetings,
I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.
Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem to be working for me. Any ideas would be appreciated. Thanks,
- Jeremy
package jab.enemy
import flash.display.MovieClip;
import flash.events.Event;
import jab.enemy.MissleDisappear;
public class DieLikeThePhishes
private var _clip2:MovieClip; // player
private var _clip3:MovieClip; //phish1
private var _clip4:MovieClip; //phish2
private var _clip5:MovieClip; //phish3
private var _clip6:MovieClip; //phish4
private var _clip10:MovieClip; // background
private var _clip11:MovieClip // missle1
private var _clip12:MovieClip // missle2
private var _clip13:MovieClip // missle3
private var _clip14:MovieClip // missle4
private var _clip15:MovieClip // missle5
private var _clip16:MovieClip // missle6
private var _clip17:MovieClip // missle7
private var _clip18:MovieClip // missle8
private var _clip19:MovieClip // missle9
private var _clip20:MovieClip // missle10
private var _clip21:MovieClip // missle11
private var _clip22:MovieClip // missle12
var ay1 = 0;var ay2 = 0;var ay3 = 0;var ay4 = 0;
var vy1 = 0;var vy2 = 0;var vy3 = 0;var vy4 = 0;
var phish1BeenHit:Boolean = false;var phish2BeenHit:Boolean = false;
var phish3BeenHit:Boolean = false;var phish4BeenHit:Boolean = false;
public function DieLikeThePhishes(clip2:MovieClip,clip3:MovieClip,clip4:MovieClip,clip5:MovieClip,clip6:M ovieClip,clip10:MovieClip,clip11:MovieClip,clip12:MovieClip,clip13:MovieClip,clip14:MovieC lip,clip15:MovieClip,clip16:MovieClip,clip17:MovieClip,clip18:MovieClip,clip19:MovieClip,c lip20:MovieClip,clip21:MovieClip,clip22:MovieClip)
_clip2 = clip2;_clip3 = clip3;_clip4 = clip4;_clip5 = clip5;_clip6 = clip6;
_clip10 = clip10;_clip11 = clip11;_clip12 = clip12;_clip13 = clip13;_clip14 = clip14;
_clip15 = clip15;_clip16 = clip16;_clip17 = clip17;_clip18 = clip18;_clip19 = clip19;
_clip20 = clip20;_clip21 = clip21;_clip22= clip22;
_clip3.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
function onEnterFrame(event:Event):void
vy1+= ay1;_clip3.y += vy1; vy2+= ay2;_clip4.y += vy2;
vy3+= ay3;_clip5.y += vy3; vy4+= ay4;_clip6.y += vy4;
if (phish1BeenHit ==false)
if(_clip3.y >620)
{_clip3.y = 620;}
if (phish2BeenHit ==false)
if(_clip4.y >620)
{_clip4.y = 620;}
if (phish3BeenHit ==false)
if(_clip5.y >620)
{_clip5.y = 620;}
if (phish4BeenHit ==false)
if(_clip6.y >620)
{_clip6.y = 620;}
if (_clip11.hitTestObject(_clip3) ||_clip12.hitTestObject(_clip3)||_clip13.hitTestObject(_clip3)||_clip14.hitTestObject(_cl ip3)||_clip15.hitTestObject(_clip3)||_clip16.hitTestObject(_clip3)||_clip17.hitTestObject( _clip3)||_clip18.hitTestObject(_clip3)||_clip19.hitTestObject(_clip3)||_clip20.hitTestObje ct(_clip3)||_clip21.hitTestObject(_clip3)||_clip22.hitTestObject(_clip3))
_clip3.scaleY = -Math.abs(_clip3.scaleY);
_clip3.alpha = 0.4;
ay1 = 3
vy1= -2;
phish1BeenHit = true;
if (_clip11.hitTestObject(_clip4) ||_clip12.hitTestObject(_clip4)||_clip13.hitTestObject(_clip4)||_clip14.hitTestObject(_cl ip4)||_clip15.hitTestObject(_clip4)||_clip16.hitTestObject(_clip4)||_clip17.hitTestObject( _clip4)||_clip18.hitTestObject(_clip4)||_clip19.hitTestObject(_clip4)||_clip20.hitTestObje ct(_clip4)||_clip21.hitTestObject(_clip4)||_clip22.hitTestObject(_clip4))
_clip4.scaleY = -Math.abs(_clip4.scaleY);
_clip4.alpha = 0.4;
ay2 = 3
vy2= -2;
phish2BeenHit = true;
if (_clip11.hitTestObject(_clip5) ||_clip12.hitTestObject(_clip5)||_clip13.hitTestObject(_clip5)||_clip14.hitTestObject(_cl ip5)||_clip15.hitTestObject(_clip5)||_clip16.hitTestObject(_clip5)||_clip17.hitTestObject( _clip5)||_clip18.hitTestObject(_clip5)||_clip19.hitTestObject(_clip5)||_clip20.hitTestObje ct(_clip5)||_clip21.hitTestObject(_clip5)||_clip22.hitTestObject(_clip5))
_clip5.scaleY = -Math.abs(_clip5.scaleY);
_clip5.alpha = 0.4;
ay3 = 3
vy3= -2;
phish3BeenHit = true;
if (_clip11.hitTestObject(_clip6) ||_clip12.hitTestObject(_clip6)||_clip13.hitTestObject(_clip6)||_clip14.hitTestObject(_cl ip6)||_clip15.hitTestObject(_clip6)||_clip16.hitTestObject(_clip6)||_clip17.hitTestObject( _clip6)||_clip18.hitTestObject(_clip6)||_clip19.hitTestObject(_clip6)||_clip20.hitTestObje ct(_clip6)||_clip21.hitTestObject(_clip6)||_clip22.hitTestObject(_clip6))
_clip6.scaleY = -Math.abs(_clip6.scaleY);
_clip6.alpha = 0.4;
ay4 = 3
vy4= -2;
phish4BeenHit = true;
if (_clip3.y > 10000)
_clip3.x = 1000 +3000*Math.random()-_clip10.x;
_clip3.y = 300;
_clip3.alpha = 1;
_clip3.scaleY = Math.abs(_clip3.scaleY);
ay1 = vy1 = 0;
phish1BeenHit = false;
if (_clip4.y > 10000)
_clip4.x = 1000 +3000*Math.random()-_clip10.x;
_clip4.y = 300;
_clip4.alpha = 1;
_clip4.scaleY = Math.abs(_clip4.scaleY);
ay2 = vy2 = 0;
phish2BeenHit = false;
if (_clip5.y > 10000)
_clip5.x = 1000 +3000*Math.random()-_clip10.x;
_clip5.y = 300;
_clip5.alpha = 1;
_clip5.scaleY = Math.abs(_clip5.scaleY);
ay3 = vy3 = 0;
phish3BeenHit = false;
if (_clip6.y > 10000)
_clip6.x = 1000 +3000*Math.random()-_clip10.x;
_clip6.y = 300;
_clip6.alpha = 1;
_clip6.scaleY = Math.abs(_clip6.scaleY);
ay4 = vy4 = 0;
phish4BeenHit = false;
var missleDisappear1 = new MissleDisappear(_clip11,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear2 = new MissleDisappear(_clip12,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear3 = new MissleDisappear(_clip13,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear4 = new MissleDisappear(_clip14,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear5 = new MissleDisappear(_clip15,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear6 = new MissleDisappear(_clip16,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear7 = new MissleDisappear(_clip17,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear8 = new MissleDisappear(_clip18,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear9 = new MissleDisappear(_clip19,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear10 = new MissleDisappear(_clip20,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear11 = new MissleDisappear(_clip21,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear12 = new MissleDisappear(_clip22,_clip3,_clip4,_clip5,_clip6,_clip10);I would approach it in much the same way as you would in java, by making getters and setters for all of your class variables.
Getters being for returning the values, Setters being for setting them.
So you would make a get function for the variable you want to access ala:
function get1PhishBeenHit():boolean {
return this.phish1BeenHit;
Then to access the value of that variable from outwith the class:
var result:boolean = ClassInstanceName.get1PhishBeenHit(); -
How Do I Run A Class From Another Class?
Hiya everyone, id like to know how to run a class from another class.
Ive got a Login class which extends a JFrame and a Personnel class which also extends a JFrame. When i press the login button (in Login class), ive got it to decide if password/login are acceptable and if they are, I want the Login class to close then run the Personnel class.
Im just after the code which says to close this class and run the Personnel class. How do i do that?
Ive researched this but couldnt get an understandable answer!
Help would be much appreciated, Ant...This is the Login Class:
public class MainMenu extends javax.swing.JFrame {
Statement statement = null;
int currentRecord;
ResultSet rs = null;
String name = null, job = null, mission = null, login = null, password = null;
String loginVal;
String passwordVal;
/** Creates new form MainMenu */
public MainMenu() {
initComponents();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = System.getProperty("user.dir") + "/src/Personnel.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + filename;
Connection conn = DriverManager.getConnection( database , "","");
statement = conn.createStatement();
System.out.println("Connected...ok");
} catch (Exception e) {
System.err.println("Got a connection Problem!");
System.err.println(e.getMessage());
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
loginVal = txtLogin.getText();
passwordVal = txtPassword.getText();
String name = null, job = null, mission = null, login = null, password = null;
try{
rs = statement.executeQuery("SELECT Login,Password FROM Personnel WHERE Login = '" + loginVal + "' ");
System.out.println("TRYING SELECT CLAUSE");
if(rs.next()){
System.out.println("THERE IS A NEXT RECORD");
login = rs.getString(1);
password = rs.getString(2);
System.out.println("GOT THE NEXT RECORD");
System.out.println(login + password);
System.out.println("Query Complete");
}catch(Exception s){
//s.printStackTrace();
System.out.println("NO RECORDS EXIST FOR THIS LOGIN ID");
if(passwordVal.equals(password)){
System.out.println("Access Granted"); //CLOSE MAIN AND RUN CONTROL CLASS
} else{
System.out.println("Access Denied"); //RE-RUN CLASS
} -
Calling a method of one class from another withing the same package
hi,
i've some problem in calling a method of one class from another class within the same package.
for eg. if in Package mypack. i'm having 2 files, f1 and f2. i would like to call a method of f2 from f1(f1 is a servlet) . i donno exactly how to instantiate the object for f2. can anybody please help me in this regard.
Thank u in advance.
Regards,
FazliThis is what my exact problem.
i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
both ShopBook.java and DataBean.java lies in the package shoppack.
in ShopBook i tried to instantiate the object to DataBean as
DataBean db = new DataBean();
it shows the compiler error, unable to resolve symbol DataBean.
note:
first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
when i'm trying to compile the ShopBook its telling this error.
hope i'm clear in explaining my problem. can u please help me?
thank u in advance.
regards,
Fazli -
Transfer assets from one asset class to another having different depreciation keys.
Hi Gurus,
I am a noob in FICO, and I am facing a problem while transferring assets from one asset class to another.
Below is the scenario.
I created two assets 100000000000-0 under asset class 4690a and 200000000000-0 under asset class 4690b. And I am trying to transfer the
asset from class 4690b to 4690a by selecting the option ‘New Asset’ in the transaction ABUMN. While doing this, I am receiving an error message as below.
'Posting with trans. type 300 not possible (No acquisition posted).'
Message No. AA324.
Diagnosis:
Transaction type 300 belongs to a transaction type group, which can only be used to post to assets to which posting has already been performed. However, no postings have been made to this asset.
Procedure:
Use a transaction type from a transactio type group, which can be used for the first acquisition to an asset.
The error is related to the transaction type which I hadn’t explicitly created anywhere. But, when checked in transaction AO76, the transaction type 300 belongs to the transaction type group 30. In this group I am not able to find any solution related to the error.
Moreover, in some of the threads in SCN, I read that modifying the transaction type group might lead to something fatal.
Kindly help me in the below.
1. What exactly the error message is related with?
2. Is there any other method to transfer the asset to another class?
Please let me know if any further details are required regarding the scenario.Hi ,
I understand that you want to transfer the old asset to new asset with different asset class with different depreciation keys and the old asset is not yet capitalized and does not have any Asset Values.
Assuming that since the First Asset is not yet capitalized, that seems to be that its just that ASset Master is created and no Asset Values appear in the Asset.(in other words no acquisition, capitalization, no dep. start etc.)..
Alternatively this asset can be advised to be blocked and flagged for deletion and create a new Asset in the new Asset Class and then capitalize the new asset by doing the acquisition according to the business process i.e. either via PO based process(GR) or Non PO based process.
The transfer of asset is required incase the old asset still have the values and you are transferring the old asset to new one with the left over values.
Also would request you to kindly share some screenshots of the AW01n of the old asset and screenshots of the AS03 to have more idea on it and provide a better solution to the same..
Warm Regards,
Vineet -
How to pass a "object" as a prameter from one java class to another java
hi experts, I want to know "How to pass and get object as a parameter from one java class to another java class". I tried follwoing code just check it and give suggetions..
import Budget.src.qrybean;
public class ConfirmBillPDF extends HttpServlet
qrybean db = new qrybean();
SimplePDFTable pdfTable = new SimplePDFTable();
pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");
}Here i want to pass db with simplePDFTableShow method. simplePDFTableShow is in another java class. So how can i do this.
And also i want to know, how this obj will get.
please help me.
Edited by: andy_surya on Jul 14, 2010 7:51 AMHi andy_surya
what is this i am not understand
pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");but i am try to solve your problem try this
qrybean db = new qrybean();
SimplePDFTable pdfTable = new SimplePDFTable();
pdfTable.simplePDFTableShow(db);and access like this in SimplePDFtable class update your method
simplePDFTable(qrybean tempDB)
// write your code
} -
HOW TO TRANSFFER THE ASSET FROM ONE ASSET CLASS TO ANOTHER
Hello,
At the time of asset uploading ,one asset was uploaded in a wrong asset class and now
I want to transffer that asset from wrong asset class to right one with depriciation value. I dont know what are to be checked before transffer and what are the process to transffer.please suggest me.
Thanks and Regards
Debjit Roy
Moderator: do not use CAPITAL letters and don't ask basic SAP questionsHi
If you have done any posting to asset which is under wrong asset class, the same values you will post thru FB01 for values only.
you need to transafer the asset no from one asset class to another asset class -
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 -
How to compile and run a .java file from another java program
hello,
can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?Well a smarter way of implementing this is by using a solution provided by Java Itself.
If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
How do i do that ??
Check out the below articles which would help you of how to do that
http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
Hope that might help :)
REGARDS,
RaHuL
Maybe you are looking for
-
Controlling - Cost Center Determination Problem - MM
Hi everyone, I have a problem concerning Cost Center determination. My Valuation Area is company code and I use division in order to input to diferent Plants. I filled all the fields on the OMJ7 transaction. I also filled all the data in the OKB9 tra
-
Lightroom 3 not accessing printer profiles
I'm not able to access newly installed Epson R3000 printer profiles when I go to print in Lightroom 3. The profiles do show up when I to print in PS3. I'm operating under 10.5.8 on my imac.
-
FCS 6 Compressor / Qmaster Issue (with QuickCluster)
I currently have a Mac Pro on the bench running OSX 10.5.8 and FCS 6. All current updates installed. Qmaster is set up with a QuickCluster, using 8 instances for all 4 cores on both CPUs. 4 GB of RAM. Using droplet to compress MOV files. After dr
-
Hi, I would like to know when it is released plug-in to recognize the Nokia 5800 with iSync Thanks ! Daniele
-
How many gb do you use when renting a movie on itune store
When renting or buying a movie on the itune store, how many GB will you normally use?