• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile a JApplet through another application  RSS feed

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a program and it has the functionality of compiling a JApplet which will be created in the same place where the original program locates. Anyway, it is not compiled, so I need to compile it when I click on the compile button. When the button is clicked, it will first find the location, and then compiles the file. Please have a look at the following sample code.



In here, the commands mentioned inside "System.out.println()" are just get printed, but the CMD do not identify them as commands, they are just "Strings" to it. How culd I make this application work? Please help...
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out ProcessBuilder and When Runtime.exec() won't. You can make the latter a bit easier by calling redirectErrorStream(true) on the ProcessBuilder before creating the Process.

And beware of Concurrency in Swing - use a SwingWorker or EventQueue.invokeLater/SwingUtilities.invokeLater.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply Rob Spoor. I will check it, and will come and post with codes, so you can correct me if there is anything wrong. But please be informed that it may take 2 to 3 days because my grandmother is sick so all of we are gonna visit her at her place.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for keeping us posted, and best wishes for a speedy recovery for your grandmother.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Thank you for keeping us posted, and best wishes for a speedy recovery for your grandmother.


Thanks Rob Spoor
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

That link has information but no coded examples, so It was very difficult for me to understand the correct thing to do. Anyway, I tried the following to open CMD but no good. Please help



Anyway, I have seen in several places people opening CMD by Runtime.getRuntime(); . But I didn't use it because I don't know how to, and that class wasn't in the ProcessBuilder link. Please help me...
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While you didn't say what "no good" means, I advise you not pursue this idea. You can't assume that a random applet client will have a compiler available - it might just have the JRE, not the JDK. Also keep in mind that this is functionality an applet is not allowed to perform without being signed.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:While you didn't say what "no good" means, I advise you not pursue this idea. You can't assume that a random applet client will have a compiler available - it might just have the JRE, not the JDK. Also keep in mind that this is functionality an applet is not allowed to perform without being signed.


This is the not working part..



It didn't do anything, no exceptions, no output, nothing!!

You can't assume that a random applet client will have a compiler available - it might just have the JRE, not the JDK.


No, actually this is a just a small code of testing. In the real program, my program will automatically generate the applet. But the case is, I can't let the generated applet to get compiled.. Please help...............
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yohan Weerasinghe wrote:This is the not working part..



It didn't do anything, no exceptions, no output, nothing!!


I was going to refer you to the "When Runtime Won't" article, but I see that Rob Spoor did that quite some time ago. If that's your code then evidently you haven't read and understood that article. I suggest you go back and do that.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I found a way to do this



Anyway not gonna use this until some one teach me what is happening here. I can understand what is cmd.exe is but what is "/c start" ???

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows already provides help for their commands. So go to your Windows command line and type "Help cmd". And "Help Start".
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Windows already provides help for their commands. So go to your Windows command line and type "Help cmd". And "Help Start".


Thanks Paul, it helped a lot.

Now, after opening the CMD, I need that to operate the following commands automatically. Here they are,

1. cd\
2. cd java\appletTest
3. javac appletTest.java

How to do this? Please help me...
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Thank you for keeping us posted, and best wishes for a speedy recovery for your grandmother.

Thanks Darryl Burke
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both Runtime.exec and ProcessBuilder allow you to specify a working folder. This takes the place of the "CD" commands.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Both Runtime.exec and ProcessBuilder allow you to specify a working folder. This takes the place of the "CD" commands.


Please, could you please give me a coded example?
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it that hard to figure out the API? Runtime.exec has two overloaded versions that take a File. This File should be the folder to execute the command in. In your case that should be new File("\\java\\appletTest"). The envp argument can remain null.
ProcessBuilder has method directory that allows you to do the same.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Is it that hard to figure out the API? Runtime.exec has two overloaded versions that take a File. This File should be the folder to execute the command in. In your case that should be new File("\\java\\appletTest"). The envp argument can remain null.
ProcessBuilder has method directory that allows you to do the same.


Great!!! Manged it. Here is the new code



Now I must execute those "javac appletTest.java" command. Will try and post back
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you for the help.. I managed to do it with this



I know I can't apply this kind of code everywhere, but for this purpose, this is what I need. Now I am gonna jump to the tutorial "When Runtime.exec() won't" to check a cored which I can apply everywhere.. I printed that whole article
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!