Solved

how launch a java prog. with a c prog?

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

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

Suggested Solutions

Title # Comments Views Activity
ejb stateless example 2 43
jboss 7.1 start up error 1 63
sql import cannot be resolved jsp 3 75
JAVA API design with micro service cloud in mind 1 79
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 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