?
Solved

how launch a java prog. with a c prog?

Posted on 1998-03-17
4
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 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