Solved

how launch a java prog. with a c prog?

Posted on 1998-03-17
4
183 Views
Last Modified: 2010-04-16
I want to know how to write a c,c++ program that will launch a java program.

Something like this:

public class Hello{
     public static void main(String[] args) {
        System.out.println("Hello world");
}
}

This gives me Hello.class when compiled.

Now if I do this:

#include <stdlib.h>

void print(void)
{
 printf("java Hello");
}

void main(void)
{
 print();
}

  I get a c program called Hello.exe

When I run Hello.exe it prints to screen:  java Hello  

This obviously doesn't invoke the jre.

Is there a way to do this?


thanks,

Mike Rutledge

0
Comment
Question by:rutledgj
  • 2
4 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1233630
There are several ways you can do this.

The simples is to have your C++ code call:

(a) Under MS Windows
   WinExec("JAVA Hello.class");

(b) Under Unix or DOS

    Exec("Java Hello.class")
or
    Spawn("Java Hello.class");

In practice, for all but the simplest apps, you would be better of if yo created a thread (fork under Unix) that makes the actual call to the Java app.

Additionaly, under MS Windows, you might want to consider creating a .PIF file (copy the Start | Programs | MS Dos Prompt PIF file ) and edit it to contain the call to your Java app.
0
 

Author Comment

by:rutledgj
ID: 1233631
Unless there is more code than you are telling me this doesn't work: Exec("Java Hello.class");
When substituted for the printf statement. I get a linking error about no extern linkage?
I'm trying to do this under dos by the way.

Any other suggestions?
0
 

Accepted Solution

by:
PEW earned 50 total points
ID: 1233632
Try this :

#include <stdlib.h>
void main(void)
{
  system ( "Java Hello.class");
}


0
 

Author Comment

by:rutledgj
ID: 1233633
this worked fine

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question