Solved

how launch a java prog. with a c prog?

Posted on 1998-03-17
4
179 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
JDeveloper 12c for 32 bit 4 35
recursion example 16 69
Java - Why doesn't this JFrame work 3 18
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now