Calling existing .h file from Java?
Hi,
I have a C .h-file that has a method defined as follows: CPXENVptr CPXopenCPLEXdevelop(int *status_p);
How do I define the function inside Java? The return type and the parameter?
Read the JNI totorial, and many, many previous psots, about "wrapper" DLLs.
Similar Messages
-
How to call a .bat file from java code?
How to call a .bat file from java code? and how can i pass parameters to that .bat file?
Thanks in advancethanks for ur reply
but still i am getting the same error.
I am trying to run a .bat file of together tool, my code looks like below
import java.lang.Runtime;
import java.lang.Process;
import java.io.File;
class SysCall{
public static void main(String args[]){
String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
//String path="D://Borland//Together6.2//bin//Together.bat ";
Runtime r= Runtime.getRuntime(); //Declare the system call
try{
System.out.println("Before batch is called");
Process p=r.exec(cmd);
System.out.println(" Exit value =" + p.exitValue());
System.out.println("After batch is called");
/*can produce errors which must be caught*/
catch(Exception e) {
e.printStackTrace();
System.out.println (e.toString());
I am getting the below exception
Before batch is called
java.lang.IllegalThreadStateException: process has not exited
at java.lang.Win32Process.exitValue(Native Method)
at SysCall.main(SysCall.java:17)
java.lang.IllegalThreadStateException: process has not exited -
How can i call forpro prg file from java
Hai friends,
I have a doubt,clear it.
how can i call forpro prg file from java file
by,
N.VijayThanks to your reply,
I have some print statements in my foxpro program file.
Then i like to invoke that foxpro file from my java file
This want i want..,
by,
N.Vijay -
I need to call a batch file from java and pass arguments to that Batch file
Hi,
I need to call a batch file from java and pass arguments to that Batch file.
For example say: The batch file(test.bat) contains this command: mkdir
I need to pass the name of the directory to the batch file as an argument from My Java program.
Runtime.getRuntime().exec("cmd /c start test.bat");
How to pass argument to the .bat file from Java now ?
regards,
Krish
Edited by: Krish4Java on Oct 17, 2007 2:47 PMHi Turing,
I am able to pass the argument directly but unable to pass as a String.
For example:
Runtime.getRuntime().exec("cmd /c start test.bat sample ");
When I pass it as a value sample, I am able to receive this value sample in the batch file. Do you know how to pass a String ?
String s1="sample";
Runtime.getRuntime().exec("cmd /c start test.bat s1 ");
s1 gets passed here instead of value sample to the batch file.
Pls let me know if you have a solution.
Thanks,
Krish -
How to modify an existing xml file from java code.
Hi
I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
For example if xml file(studlist.xml) is as below:
<?xml version="1.0" encoding="UTF-8"?>
<StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
<Student>
<Name>ram</Name>
<Age>27</Age>
</Student>
<Student>
<Name>sham</Name>
<Age>26</Age>
</Student>
</StudentList>
Now suppose i have set name to victor using student.setName,
and set age to 20 using setAge from javacode,
the new xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
<Student>
<Name>ram</Name>
<Age>27</Age>
</Student>
<Student>
<Name>sham</Name>
<Age>26</Age>
</Student>
</StudentList>
<Student>
<Name>victor</Name>
<Age>20</Age>
</Student>
As observed this is not a valid xml file.But how can i modify without any errors?I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
// gets the root element of the specified file (code not shown)
Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
// write a new student element
Element student = document.createElement("Student"); // creates the new student
rootElement.appendChild(student); // ***appends it to the root element***
Element name = document.createElement("Name"); // creates the name element
name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
student.appendChild(name); // appends the name to the student
Element age= document.createElement("Age"); // creates the age element
age.appendChild(document.createTextNode("26")); // adds the age text to the age element
student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM -
How to Call a batch file from Java ?
In my java application I have to call a .bat (Batch file) file.
I found that already. Eventhough that is slightly differ from yours.
.exec("cmd /c start x.bat");
Anyhow
Thanks yarr.
My E-Mail ID is [email protected] -
Call existing C apliction from java
hi all,
I try this
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html for JNI.
we need to write the native method implementation in such a way that the method signature should exactly match the method signature created in the header file.
i want to provide interface to existing c application without distubing code taking input from stdin before
now i want java to pass that parameter and result return back in java agingYou don't need JNI for this task. Runtime.exec() is enough. Run you C application and pass arguments using stream then get result using other stream.
-
Calling nested Batch files from Java
Hi,
I have a java program which loops through a list of batch files, executing each one. This works fine. My problem is that each batch file I execute contains a call to execute a further batch file.
The second(nested) batch file never gets run. The java program completes sucessfully though. Any ideas of a way around this?
Code:
while (batFileToken.hasMoreTokens()){
String batFileName = batFileToken.nextToken();
Process process = load.exec("cmd.exe /c "+batFileName);
process.waitFor();
}Each batFileName it executes contains the below command:
call test.battest.bat never executes.Check this link..
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
the way to make sure process is completed.. is
try{
Process proc = Runtime.getRuntime().exec(optimizer.exe);
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
errorGobbler.start();
outputGobbler.start();
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
catch (IOException ex1) {
System.out.println("Error in Starting Optimizer");
catch (Throwable t) {
t.printStackTrace();
class StreamGobbler extends Thread {
InputStream is;
String type;
OutputStream os;
StreamGobbler(InputStream is, String type) {
this(is, type, null);
StreamGobbler(InputStream is, String type, OutputStream redirect) {
this.is = is;
this.type = type;
this.os = redirect;
public void run() {
try {
PrintWriter pw = null;
if (os != null)
pw = new PrintWriter(os);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null) {
if (pw != null)
pw.println(line);
System.out.println(type + ">" + line);
if (pw != null)
pw.flush();
catch (IOException ioe) {
ioe.printStackTrace();
} -
How to access methods in existing dll file from java
I have a dll file and that file contains two methods.
Now I would like to access those two methods in java program.
How to access these methods.
Give me the sample code for this problem.http://forum.java.sun.com/thread.jspa?threadID=757125&tstart=0
-
Need urgent help. Calling of exe files from java program
This program can execute small .exe files that donot take inputs but doesn't work for exe files that takes input. what could be the problem.
Server code :-
import java.io.*;
import java.net.*;
public class Server1 {
private Player[] players;
private ServerSocket server;
private ExecHelper exh;
String command = null;
String message = null;
public Server1() {
players = new Player[5];
try {
server = new ServerSocket( 12345, 5 );
System.out.println("Server started...");
System.out.println("Waiting for request...");
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
} //end Server constructor
public void execute() {
for( int i = 0; i < players.length; i++ )
try {
players[i] = new Player( server.accept() );
players.start();
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
public static void main( String args[] ) {
Server1 ser = new Server1();
ser.execute();
System.exit( 1 );
private class Player extends Thread {
private Socket connection;
private ObjectOutputStream output;
private ObjectInputStream input;
public Player( Socket socket ) {
connection = socket;
try {
input = new ObjectInputStream( connection.getInputStream());
output = new ObjectOutputStream( connection.getOutputStream());
output.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
public void run() {
try {
message = "Enter a command:";
output.writeObject( message );
output.flush();
do {
command = ( String ) input.readObject();
String osName = System.getProperty( "os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 2000" )) {
cmd[0] = "cmd.exe";
cmd[1] = "/c";
cmd[2] = command;
else if( osName.equals( "Windows NT" ) ) {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = command ;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec( cmd );
exh = new ExecHelper( proc, output, input);
} while( !command.equals( "TERMINATE" ) );
catch( Throwable t ) {
t.printStackTrace();
} //end class Player
public class ExecHelper implements Runnable {
private Process process;
private InputStream pErrorStream;
private InputStream pInputStream;
private OutputStream pOutputStream;
private InputStreamReader isr;
private InputStreamReader esr;
private PrintWriter outputWriter;
private ObjectOutputStream out;
private ObjectInputStream in;
private BufferedReader inBuffer;
private BufferedReader errBuffer;
private Thread processThread;
private Thread inReadThread;
private Thread errReadThread;
private Thread outWriteThread;
public ExecHelper( Process p, ObjectOutputStream output, ObjectInputStream input ) {
process = p;
pErrorStream = process.getErrorStream();
pInputStream = process.getInputStream();
pOutputStream = process.getOutputStream();
outputWriter = new PrintWriter( pOutputStream, true );
in = input;
out = output;
processThread = new Thread( this );
inReadThread = new Thread( this );
errReadThread = new Thread( this );
outWriteThread = new Thread( this );
processThread.start();
inReadThread.start();
errReadThread.start();
outWriteThread.start();
public void processEnded( int exitValue ) {
try {
Thread.sleep( 1000 );
catch( InterruptedException ie ) {
ie.printStackTrace();
public void processNewInput( String input ) {
try {
out.writeObject( "\n" + input );
out.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
public void processNewError( String error ) {
try {
out.writeObject( "\n" + error );
out.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
public void println( String output ) {
outputWriter.println( output + "\n" );
public void run() {
if( processThread == Thread.currentThread()) {
try {
processEnded( process.waitFor());
catch( InterruptedException ie ) {
ie.printStackTrace();
else if( inReadThread == Thread.currentThread() ) {
try {
isr = new InputStreamReader( pInputStream );
inBuffer = new BufferedReader( isr );
String line = null;
while(( line = inBuffer.readLine()) != null ) {
processNewInput( line );
catch( IOException ioe ) {
ioe.printStackTrace();
else if( outWriteThread == Thread.currentThread() ) {
try {
String nline = null;
nline = ( String ) in.readObject();
println( nline );
catch( ClassNotFoundException cnfe ) {
// cnfe.printStackTrace();
catch( IOException ioe ) {
ioe.printStackTrace();
else if( errReadThread == Thread.currentThread() ) {
try {
esr = new InputStreamReader( pErrorStream );
errBuffer = new BufferedReader( esr );
String nline = null;
while(( nline = errBuffer.readLine()) != null ) {
processNewError( nline );
catch( IOException ioe ) {
ioe.printStackTrace();
Client code :-
// client.java
import java.io.*;
import java.net.*;
public class Client {
private ObjectOutputStream output;
private ObjectInputStream input;
private String chatServer;
private String message = "";
private Socket client;
public Client( String host ) {
chatServer = host;
private void runClient() {
try {
connectToServer();
getStreams();
processConnection();
catch( EOFException eofe ) {
System.err.println( "Client terminated connection ");
catch( IOException ioe ) {
ioe.printStackTrace();
finally {
closeConnection();
} //end method runClient
private void connectToServer() throws IOException {
System.out.println( "Attempting connection...\n");
client = new Socket( InetAddress.getByName( chatServer ), 12345);
System.out.println( "Connected to : "+ client.getInetAddress().getHostName());
private void getStreams() throws IOException {
output = new ObjectOutputStream( client.getOutputStream());
output.flush();
input = new ObjectInputStream( client.getInputStream());
private void processConnection() throws IOException {
while( true ){
try {
message = ( String ) input.readObject();
System.out.print( message );
InputStreamReader isr = new InputStreamReader( System.in);
BufferedReader br = new BufferedReader( isr );
String line = null ;
line = br.readLine();
output.writeObject(line);
output.flush();
catch( ClassNotFoundException cnfe) {
System.out.println( "\nUnknown object type received");
} //end processConnection
private void closeConnection() {
System.out.println( "\nClosing connection");
try {
output.close();
input.close();
client.close();
catch( IOException ioe ) {
ioe.printStackTrace();
public static void main( String args[] ) {
Client c;
if( args.length == 0 )
c = new Client( "127.0.0.1" );
else
c = new Client( args[0] );
c.runClient();maybe you should
1. Use code tags so the posted code is understandable
2. Stop marking your post urgent, that just puts peoples backs up
3. Stop posting the question every couple of hours on every imaginable forum.. Post it once and start a single dialog -
Calling C Functions in existing DLL's from Java
Hi Guys ,
The tutorial in this site talks about creating ur own DLL's and then calling them from Java . I need to call C functions in existing DLL's from Java . How do I go about doing this ? . Any help on this would be much appreciated.
regards
muraliWhat you are interested in can be done with what's called "shared stubs", from the JNI book (http://java.sun.com/products/jdk/faq/jnifaq.html), although you don't need the book to do it (I didn't).
The example code will call functions with any number and kind of parameters, but doing that requires some assembly language. They supply working examples for Win32 (Intel architecture) and Solaris (Sparc).
If you can limit yourself to functions to a single function signature (number and types of parameters), or at least a small set that you know you'll call at compile time, you can modify the example so that the assembly language part isn't needed, just straight C code.
Then you'll have one C library that you compile and a set of Java classes and you can load arbitrary functions out of arbitrary dynamic libraries. In my case you don't even have to know what the libraries and functions are ahead of time, the user can set that up in a config file.
You mentioned doing this with Delphi. One thing to watch out for is C versus Pascal (Win32) function calling convention. A good rule of thumb; if it crashes hard, you probably picked the wrong one, try the other. :-) -
How to call a .jar file from a java bean?
any body knows how to call a .jar file from a java bean?
Crosspost!
http://forum.java.sun.com/thread.jspa?messageID=4349619 -
How to edit the existing data in the XML file from java programming.
Hi all
i am able to create XML file with the sample data as below from java programming.
i need sample code on how to edit the existing data in the XML file?
for example
<?xml version="1.0"?>
<mydata>
<data1>
<key1>467</key1>
<name1>Paul</name1>
<id1>123</id1>
</data1>
<data2>
<key2>467</key2>
<name2>Paul</name2>
<id2>123</id2>
</data2>
</mydata>
i am able to insert the data in the XML.
now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
Regards
Sunil
[points will be always rewardable]hi
u need a parser or validate the xml file for to read the xml file from java coding u need for this
xml4j.jar u can download this file from here
http://www.alphaworks.ibm.com/tech/xml4j
or we can use the SAX(simple API for XML)
some sample applications for this
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
http://www.xml-training-guide.com/e-xml44.html
let me know u need any other info
bvr -
Call .bat file from java code
I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt
importcli.exe db1800 C:\Importcli\files\*.mdbmagaupe wrote:
I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt
importcli.exe db1800 C:\Importcli\files\*.mdb
Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
[http://www.google.com/search?hl=en&q=call+.bat+file+from+java] -
I wants to call .Exe file from Java Programme
I wants to call .Exe file from Java programme. Please give answer with example. This very urgent. Help me
hi
u can use Runtime.exec() method in java.lang package
to execute exe files
regards
pnp
Maybe you are looking for
-
HT4623 What if I have no wifi connection to download software updates on iPhone 4S
I have no available wifi in order to download updates on my iPhone 4S. Is there some kind of download I can use over the 3G network to update my phone with?
-
How can I set up an email where the mail account is totally different to the email address?
The email account (and password related to it) is in the form "xxxxxx.ndonet.com." The email address is "xxxxxx.ndirect.co.uk." There don't seem to be many email clients that allow this and at present I am having to use Pegasus. I have tried manual c
-
Auto creation of notification for vendor problems
Hi, pls advise how to generate notificatin for vendor problems during goods receipt. can it be possible to generate automatically when there is problem for the vendor for the goods which are subjected to GR. Pls advise.
-
Change in Cost Allocation Flexfield
Hello, Client is currently using HRMS for the past one year. Now we need to make a small change in the Cost Allocation Flexfield structure. How will this affect the past data. How can we address this scenario. I seek your expert advise to handle this
-
Is the Apple TV "buggy"?
I got my ATV (2nd generation) for Christmas and have had a lot of problems with it. Mainly, sound disappears from time-to-time. I can turn off my system. When I turn it back on, there is no audio. 'Have to unplug the HDMI (to my AVR) and/or power to