[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how launch a java prog. with a c prog?

Posted on 1998-03-17
4
Medium Priority
?
189 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

656 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