Calling java from inside an Active Server Page.
Is it possible to call a java application from inside an ASP ?
I can't write COM. Just Java. But IIS is all I have access to at this time.
thanks,
nupevic
Yes, I did a year ago (a PDF creating app); however I've forgotten how. Microsoft had a register-tool I believe.
Please wait on someone else's (with a better recall) reply.
Similar Messages
-
RE: ActiveX control and Active Server Pages?
Martin, if it works in standalone VB program but not in an .asp page
through VBScript, I guess the reason may be the type mismatch on the
parameters of the ActiveX automation methods. VBScript is a subset of VB
and only supports the OLE data type VARIANT for calling the OLE
interface. The Conductor ActiveX control probably requires the actual
data types, such as long, BSTR, and so on, to be used on the parameters.
As a result, VBScript cannot call the methods on the control. One
workaround you can try is to create your own ActiveX control which is
simply a wrapper for calling the Conductor control. Its parameter types
use VARIANT and you do the data conversion in your wrapper code. Hope
this helps.
Lenny Hon
Descartes Systems Group
-----Original Message-----
From: Martin Peters [SMTP:[email protected]]
Sent: Monday, July 27, 1998 10:50 AM
To:
Subject: ActiveX control and Active Server Pages?
Hello Forte users,
Did anyone try to use the ActiveX control that ships with Conductor
1.0G in an Active Server Page?
I tried to use the ActiveX control without luck, so a sample would be
appreciated. The code
works fine in Visual Basic.
Below the code:
<HTML>
<BODY>
<%
Set thisDirectory =
Server.CreateObject("CONDUCTORCLIENT.WFDirectoryServiceCtl.1")
Set thisEngine = thisDirectory.WFFindEngine("ceengine", "centrale")
Set thisUser =
Server.CreateObject("CONDUCTORCLIENT.WFUserProfileDescCtrl.1")
thisUser.New
thisUser.ProfileName = "MiniUP"
thisUser.userName = "martin"
' The following call fails: Invalid procedure call or argument:
'thisEngine.OpenSession'
Set thisSession = thisEngine.OpenSession("CREATE", thisUser, "martin",
0)
Set thisProcess = thisSession.CreateProcess("MiniPD", Empty)
thisSession.CloseSession (WFSESSION_TERMINATED)
%>
</BODY>
</HTML>
Martin Peters
COMPAQ
NSIS - AD&I - Application Connect
email <[email protected]>
phone: +31 (30) 2834902
fax: +31 (30) 2834980
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive
<URL:http://pinehurst.sageit.com/listarchive/>-
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>I don't have 6.1 in front of me now. I came up with a workaround for my application when I encounted this problem. I created an attribute node for the container and the tab control. Whenever the tab control was not on the page with the control, I made the container invisible. This then hid the activeX control.
-
Getting - Active Server Pages error 'ASP 0126'
I get the following error when applying the upload function
to my already made form.
Active Server Pages error 'ASP 0126'
Include file not found
/sitename/sitepage.asp, line 2
The include file 'dwzUpload/DefineVariable.asp' was not
found.
The top of my code on "Sitepage.asp" looks like this:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="dwzUpload/DefineVariable.asp" -->
<!--#include file="Connections/connBest.asp" -->
<%
'* ONLY UPLOAD *
http://www.DwZone-it.com *
server.ScriptTimeout = 5400
Dim RG_Connection, RG..........
I can supply more information if need be. Your help is
greatly appreciated!
Thanks,
Matt"dwzUpload/DefineVariable.asp" location is:
C:\inetpub\wwwroot\sitename\dwzUpload.
So it's located in the site root, inside the dwzUpload
folder.
I am currently running the site on my local machine with
IIS7.
I don't get an error if I remove the 'upload' function on the
site, but the site needs to offer upload of image files. Not sure
where to go to from here.
Thanks,
Matt -
Problem calling java from vb via activex bridge
I am trying to call java from vb via ActiveX Bridge and I am running into problems. I would appreciate any help.
I am using Visual Basic 2010 express, and Java JDK 1.6.0_16. I have used the http://download.oracle.com/javase/1.4.2/docs/guide/beans/axbridge/developerguide/index.html page as a guideline. To try to make it work I took the following steps:
1. Wrote a very simple java class (below):
package xxx;
import java.io.Serializable;
public class axb implements Serializable {
public int get_axb_Handle() {
int Address = 12345678;
return Address;
2. After I compiled, and created the jar file. I built the dll using the following command:
"C:\Program Files\Java\jdk1.6.0_16\bin\packager" -out "C:\Program Files\Java\jdk1.6.0_16\jre\axbridge\bin" E:\axb\dist\axb.jar xxx.axb
3. I then registered using: regsvr32 axb.dll
4. In Visual Basic Express IDE I use Project -> Add Reference to add Iterop.axb (dump below), and axb namespace
5. In my basic code I use the following lines
Dim axb1 As axb.axb
axb1 = New axb.axb <== Crash here with AccessViolationException ( full exception below)
What am I missing? Any help would be greatly appreciated
Thanks
Iterop.axb partial dump
___[MOD] C:\Documents and Settings\Elie A. Cohen.USINC022\My Documents\Visual Studio 2010\Projects\Repo API Example\Repo API Example\obj\x86\Release\Interop.axb.dll
| M A N I F E S T
|___[NSP] axb
| |___[INT] axb.axb
| | | .class interface public abstract auto ansi import /*02000006*/
| | | implements axb.axbDispatch/*02000003*/
| | | implements axb.axbSource_Event/*02000005*/
| | | .custom /*0C000018:0A000001*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.GuidAttribute/*01000002*/::.ctor(string) /* 0A000001 */ = ( 01 00 24 34 45 36 44 30 44 41 38 2D 36 41 45 44 // ..$4E6D0DA8-6AED ...
| | | .custom /*0C000019:0A000007*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.CoClassAttribute/*01000009*/::.ctor(class [mscorlib/*23000001*/]System.Type/*01000007*/) /* 0A000007 */ = ( 01 00 0C 61 78 62 2E 61 78 62 43 6C 61 73 73 00 // ...axb.axbClass. ...
| |
| |___[CLS] axb.axbClass
| | | .class public auto ansi import /*02000004*/
| | | implements axb.axbDispatch/*02000003*/
| | | implements axb.axb/*02000006*/
| | | implements axb.axbSource_Event/*02000005*/
| | | .custom /*0C00000F:0A000008*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.ClassInterfaceAttribute/*0100000A*/::.ctor(int16) /* 0A000008 */ = ( 01 00 00 00 00 00 ) ...
| | | .custom /*0C000010:0A000009*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.ComSourceInterfacesAttribute/*0100000B*/::.ctor(string) /* 0A000009 */ = ( 01 00 0F 61 78 62 2E 61 78 62 53 6F 75 72 63 65 // ...axb.axbSource ...
| | | .custom /*0C000011:0A000001*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.GuidAttribute/*01000002*/::.ctor(string) /* 0A000001 */ = ( 01 00 24 43 44 42 46 36 42 33 33 2D 45 32 33 46 // ..$CDBF6B33-E23F ...
| | | .custom /*0C000012:0A000002*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.TypeLibTypeAttribute/*01000003*/::.ctor(int16) /* 0A000002 */ = ( 01 00 02 00 00 00 ) ...
| | |___[MET] method .ctor : void()
| | |___[MET] method equals : bool(object)
| | |___[MET] method getClass : object()
| | |___[MET] method get_axb_Handle : int32()
| | |___[MET] method hashCode : int32()
| | |___[MET] method notify : void()
| | |___[MET] method notifyAll : void()
| | |___[MET] method toString : string()
| | |___[MET] method wait : object(object,object)
AccessViolationException exception
System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at WindowsApplication1.Form1.getPatientHandle_Click(Object sender, EventArgs e) in C:\Documents and Settings\Elie A. Cohen.USINC022\my documents\visual studio 2010\Projects\Repo API Example\Repo API Example\Repo API Example.vb:line 13
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:In case you haven't figured it out already... Or if anyone else is curious... Or for myself when I get old and forgetful...
h2. Object Creation
For starters, when you create an ActiveX object from within VB, use:
Set myObject = CreateObject("JavaObject.Bean")When I refer to JavaObject.Bean, I'm meaning the full object name + ".Bean". So, in your case, you should use:
Set myObject = CreateObject("xxx.axb.Bean")h2. Location
The .dll file must be located in the JRE that is used at the time of calling. Meaning, the .dll file must be placed under <jre_home>\axbridge\bin and registered there.
In your case:
DLL:
C:\Program Files\Java\jre6\axbridge\bin
Jar:
C:\Program Files\Java\jre6\axbridge\libh4. A Note:
The only supported JRE is a 32bit version as far as I know with regards to the ActiveX bridge. Just like the packager.exe can only be found in the 32bit JDK.
h2. Methods
h3. Object Types
ActiveX Bridge does not support passing literals or arrays. However, it does support passing java's primitive data types as Objects.
Simply meaning:
h4. Invalid:
public int get_axb_Handle() {
int Address = 12345678;
return Address;
}h4. Valid:
public Integer get_axb_Handle() {
int Address = 12345678;
return Address;
}On a normal circumstance, there's little difference between the two methods. However, in the second example, the JVM does a typecast from a literal data type to a object data type, resulting in a valid object to pass through to Visual Basic. Now, obviously there are multiple ways to do a proper change, new Integer(int) for example. It doesn't matter to me. At the end of the day, you have to pass an object.
As a side note, the same idea applies when receiving data from Visual Basic.
h4. Invalid:
public void set_axb_Handle(int newHandle) {
int Address = newHandle;
}h4. Valid:
public void set_axb_Handle(Integer newHandle) {
int Address =newHandle; -
Error : OraOLEDB (0x80004005) & Active Server Pages error 'ASP 0115'
I have developed a project and opened recordsets as mentioned below
With Rs
.Open "Query",Application("Cn")
If not (.eof and .bof) then
.Movefirst
End If
End with
The error 'OraOLEDB' showing at .Open statement. When we refresh page multiple times then Active Server Pages ASP 0115 error occures. Which is get resolved only when I reboot the Web Server or restart the web services.
OraOLEDB error raises frequently while application running. In between some time it skip the error and show the page perfectly.
Co-operate me just by suggesting how to resolve this problem.Row-00001 occurs when a windows api call to allocate memory failed.
This can occur due to a memory leak, or memory fragmentation.
Have you monitored private bytes and virtual bytes?
There was also an issue in old versions of the provider that caused this, so make sure your oledb provider and oracle client software are up to date.
Hope it helps,
Greg -
To call Java Procedure inside Forms6i
How do i call a java procedure (Stored either in Oracle8i database or application server )from Oracle Forms6i trigger / procedure.If this possible please let me know.
Your help in this regard would be appreciatedFor java procedures in the database (stored java procedures) you just call the pl/sql wrapper function that was created for the java function.
To call java functions on the application server you can use the java importer utility available with forms6i patch2 and above. -
Advantages and Disadvantages of calling java from PL/SQL
Hi,
I have one doubt. What are all the advantages and disadvantages of the calling java from PL/SQL?
In actual scenario the java program will be in the Application server side. It will do the operation and it will store the result in Data base. But in this case (calling java from PL/SQL), we are loading the java program in the Data base and it is doing the operations.
I have seen many posts are coming regarding loading jar files into the database. Actually the jar will deploy in to Application server. Is there any difference instead of keeping in the Application server side?
Then I have read,
advantages:
-> java having lot API's. so PL/SQL can use that API's.
-> if we can not do anything in PL/SQL. we can do it using this mtd(calling java from PL/SQL).
My questions:
-> could you explain what are all the things we can not do but we can do using "calling java from PL/SQL" method?
-> is there any other advantages?
Disadvantages:
-> the performance is very slow in calling java from PL/SQL.
My questions:
-> Then why others are loading java files and jar files into database?
-> is there any other disadvantages?
Could you explain about this one? It will be more helpful to others also…
Regards,
kkHi,
You can read the free first chapter of my book @ http://www.amazon.com/gp/product/1555583296/ (see details then Excerpt)
Kuassi http://db360.blogspot.com -
Revision: 21661
Revision: 21661
Author: [email protected]
Date: 2011-07-21 06:21:07 -0700 (Thu, 21 Jul 2011)
Log Message:
Avoid calling throwNotSubscribedException() from inside synchronized blocks to prevent potential issues acquiring the lock.
Checkin-Tests: Pass
QA: Yes
Doc: No
Modified Paths:
blazeds/trunk/modules/core/src/flex/messaging/client/FlexClient.java -
JCo connectivity is used to call RFCs from Java. can i call Java from abap?
thanks in advance.....
regards,
SundararamaprasadHi Sundar ,
This link will surely give u an idea about calling java fro ABAP using Jco.
http://www.thespot4sap.com/Articles/SAP_Netweaver_Java_Connector.asp
regards,
aravindh. -
Hi all,
I have installed JCO & created the RFC in SAP. i have used below code to test my RFC connection & it's working fine.
But In the below report, where to call the JAVA Program & what code i should use to call java code .
Actually my ABAP requirement is to download a file. Then i need to call JAVA program, inside ABAP, to encrypt the downloaded file. Here, Java program is used to encrypt the file. Now question is, how to call the Java program inside the ABAP code. Please advice with the code sample. Thanks a lot.
REPORT z_jco_test.
PARAMETERS: requtext LIKE sy-lisel.
DATA: echotext LIKE sy-lisel,
resptext LIKE sy-lisel,
rfctest TYPE TABLE OF rfctest,
wa_rfctest TYPE rfctest.
wa_rfctest-rfcdata1 = requtext.
wa_rfctest-rfcdata2 = 'Hello World'.
APPEND wa_rfctest TO rfctest.
CALL FUNCTION 'RFC_PING'
DESTINATION 'JCO'.
CALL FUNCTION 'STFC_CONNECTION'
DESTINATION 'JCO'
EXPORTING
requtext = requtext
IMPORTING
echotext = echotext
resptext = resptext
TABLES
rfctest = rfctest.
WRITE: 'Echo Text: ', echotext.
WRITE: 'Response Text: ', resptext.
LOOP AT rfctest INTO wa_rfctest.
WRITE: / 'rfcdata1: ', wa_rfctest-rfcdata1.
WRITE: / 'rfcdata2: ', wa_rfctest-rfcdata2.
ENDLOOP.Hi,
You might accomplish your goal using external operating system commands.
1) Define in SM69 an external command, letu2019s say ZJAVA. This command will execute a script on the operating system, letu2019s call it calljava.sh.
2) In script calljava.sh you just call java, passing some parameters. For example, java $1 $2 $3 $4 $5 $6 $7
3) In your ABAP program you call the ZJAVA external command and pass parameters to it. Of course, one of the parameters must be your Java program name.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = l_command
additional_parameters = l_param
trace = 'X'
IMPORTING
status = l_status
exitcode = l_exitcode
TABLES
exec_protocol = l_exec_protocol_itab
EXCEPTIONS
no_permission = 1u2026 -
Can ActiveX bridge used for calling Java from Delphi?
Also trying to solve this problem, after creating the bean i packaged/registered it successfully, (tested the bean using beanbox, works perfectly) then tried calling it via createoleobject in delphi 7
(*Code Snip *)
Var
v : variant;
begin
try
v := createoleobject(Edit1.text); // my class name ie WorldPort.Bean (also tried WorldPort.Bean.1
except on e:exception do
showmessage(e.Message)
end;
end;
(*Code Snip*)
After this simple code failed i started backtracking , eventually after getting "Access Violation...etc in axbridge.dll" all the time. tried delphi "import activex control" got the same access violation.
Decided to test the example from http://java.sun.com/j2se/1.4.2/docs/guide/beans/axbridge/developerguide/examples.html........ they both crashed on execution (calc.exe and boundprop.exe).
After this failed I tested these example classes on another machine, both crashed again.....
Also tried this experiment in VC++ , after adding the class to the Toolbox , i try to drop it onto a form, once again access violation.**PS**
('You will need VC++ and the Microsoft SDK to build the dll, download c++beta for free from microsoft site it you need it')** and a simple cmd file todo the job would look something like this:
echo - ** Build Java ActiveX Bridge **
echo Make sure these folders exist in jre--> axbridge\lib and axbridge\bin
cd\SDK\jre\axbridge\bin
set path=%path%;C:\MSDN\Bin;C:\VisualC++\lib
echo path
javac WorldPort.java
jar cmf Manifest.txt WorldPort.jar WorldPort.class
"C:\SDK\bin\packager.exe" -clsid {162193C4-AD5C-4A06-9F88-A737AE9B43AD} -out "C:\SDK\jre\axbridge\bin" WorldPort.jar WorldPort-reg
*** After running this cmd you will find the dll in bin folder and the jar in lib folder..***
Must Read:http://java.sun.com/j2se/1.4.2/docs/guide/beans/axbridge/developerguide/index.html
Hope some of this helps , if you have successfully created / installed/ used a "JavaActiveX" in Delphi , i would really like to try replicate it on my machine.. -
Deploy XI java Proxy inside JBoss application server
Hello,
Can I deploy XI java Proxy inside JBoss application server
Appreciate you response.
ThanksHi,
<b>Yes</b>
You can deploy your Java Proxy inside JBoss Server (in any Application server). But this will be possible only for Client Java Proxy and not for Server Java Proxy.
I have succesfully completed those scenarios.
After generating Client Java proxy, create EJB application with generated Java classes for proxies and deploy it in JBoss.
Then you can access that EJB to pass inputs either in standalone application or some JSP.
Regards,
Uma -
Is it possible to call java from Sybase trigger ? If so can you please supply example or URL to one ? Alternative solution is to call shell script from sybase trigger (as app is based on Solaris).
Regards
MichalThank for your opinion, but what idea is better ?Doing things in the middle tier, where Java lives.
Ever heard of event-based trading systems?
pooling a table every 30 sec. ?. I need to implment
real-time system which process each trade from table
once it appears there.Sounds like you have it backwards - you're trying to drive Java from the database.
I think it'd be better to write that event-based system in Java and leave the database just for persistence.
GigaSpaces and their ilk are being used this way for highly transactional trading systems. Maybe you could see how they're doing it.
% -
ResourceBundle throws MissingResourceException when calling Java from C
All,
Our code calls Java from C application.
The C code create JVM using JNI_CreateJavaVM. Due to internal design issues we don't
create the JVM with a "-classpath" option.
After creating the JVM, we create a ClassLoader (URLClassLoader), with a URL list as it's classpath.
The last step in the C code is to load a Java class using the C reference to URLClassLoader.loadClass
(I will refer to this class as classA), and than call one of it's static methods.
Please notice that classA is not instantiated, we call a static method.
At this point we are moving to the Java code...
In the Java static method we call ResourceBundle.getBundle("resources.messages"),
the result is ResourceBundle throws MissingResourceException.
- The JAR hosting "resources/messeges.properties" (refer as jarA) is include in the
ClassLoader URL paths we used for loading the Java class.
- Using a debugger we can see that ClassLoader.getSystemClassLoader() don't contain
jarA in it's URL list.
- Using the debugger we see that classA.class.getClassLoader() does contain
jarA in it's URL list.
After some investigation we see that ResourceBundle.getBundle calles to ResourceBundle.getLoader:
private static ClassLoader getLoader() {
Class[] stack = getClassContext();
/* Magic number 2 identifies our caller's caller */
Class c = stack[2];
ClassLoader cl = (c == null) ? null : c.getClassLoader();
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
return cl;
} getClassContext() - native method, this can explain the why the above work fine for Windows.
I suspect the problem raised in the above code. Since I couldn't get a debug
version of rt.jar for Solaris, I need some help.
Our environment is Solaris 8, Java 1.5.
Please note that the same code works fine on WindowsXP with the same Java version!
Thanks,
AviI was thinking JVM should the classpath when it is invoked. But obviously it is not and we need to assign the classpath ourselves when invoking from native side. Thanks for pointing that out. For other people's benefit the following is the code piece I for initializing JVM.
char* str1;
char* str2;
char* classpath;
str1 = "-Djava.class.path=";
str2 = std::getenv("CLASSPATH");
classpath = (char*)malloc(strlen(str1) + strlen(str2) + 1);
strcpy(classpath, str1);
strcat(classpath, str2);
if (str2 == NULL) {
printf("CLASSPATH environment variable is not defined.");
exit(1);
m_VmArgs.version = JNI_VERSION_1_4;
m_options[0].optionString= classpath;
m_VmArgs.options = m_options;
m_VmArgs.nOptions = 1;
m_VmArgs.ignoreUnrecognized = JNI_TRUE;
JNI_GetDefaultJavaVMInitArgs(&m_VmArgs);
/* Create the Java VM */
m_Res = JNI_CreateJavaVM(&m_Jvm, (void**)&m_Env, &m_VmArgs);
if (m_Res < 0) {
printf("Can't create JVM\n");
exit(1);
thanks,
chancellor -
Questions abt. calling Java from C
I have a java class that contains a method I need to make accessable to C functions. It looks something like this:
public class ExportName
private SomeObj theObj;
public ExportName(SomeObj theObj)
this.theObj = theObj;
} //end ExportName
public String getName()
return theObj.getName();
public native String getNameJNI();
}Using javah I have my ExportName.h, and I'm in the process of writing ExportName.c:
#include <stdio.h>
#include <jni.h>
#include "ExportName.h"
JNIEXPORT jstring JNICALL Java_ExportName_getNameJNI (JNIEnv *, jobject)
jclass cls = (*env)->GetObjectClass(env, obj);
jMethodID mid = (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String");
if (mid == 0)
return;
} /* end if */
}I have 2 questions:
(1)At some point, I need to actually call the java method using
(*env)->Call<TYPE>Method(env, obj, mid);
What type should I use here (CallWhatMethod)?
(2)Also, I need to create genuine C wrappers for these methods. How do I hand off the jstring returned by this JNI C code to the ANSI C method that calls it? I know that there is a conversion along the lines of:
const char str = (env)->GetStringUTFChars(env, <<JSTRING HERE>>, 0);
Can I just put the call to the JNI method where the jstring variable name goes?
Any help would be appreciated. I have already read the Java tutorial on JNI, so please don't respond just to tell me to go there.
Thanks!If that is the case, then your starting point is not javah, but to investigate the invocation API, after which you will call java methods from C.
Well, the Invocation API is mostly orthogonal to whether you are calling Java from C or vice versa. The Invocation API is mostly about creating/destroying VMs. You can call Java methods from a flat C application or you can call Java methods from C from within Java native methods.
If you want to call Java from C, you need to use the methods you're using like GetMethodID, CallXXXMethod, etc...
In your particular example, if you wanted to call ExportName.getName(), you would use CallObjectMethod. You would cast the result to a jstring, and then use GetStringUTFChars, ReleaseStringUTFChars, etc...
God bless,
-Toby Reyelts
For a solution to all your JNI woes, check out Jace - http://jace.reyelts.com/jace
Maybe you are looking for
-
Retrieve data from SQL database and put into a table
Hi all, i encountered this error while trying to create a table in 1 of my panels: C:\Documents and Settings\L311c01\Desktop\FYPJ Java2\RFIDLogistics.java:25:{color:#ff0000} cannot find symbol symbol : class ResultSetTable {color}location: class jdbc
-
JPA, Toplink, Query with getSingleResult returns Vector, should it?
I don't understand why when I do a simple query "Select count(*) From ...." and get use the EntityManager my code is something like this: getEntityManager().createNativeQuery(sql).getSingleResult() and what I get is a Vector object that has inside a
-
How to upgrade from CS6 to CC?
I want to upgrade from CS5.5 or CS6 to CC. The procedure I need to follow is -> Adobe Creative Cloud Packager. What I did? 1. On a clean system, I started the Packager to make the package. 2. No problems installing this package on a clean system. Wha
-
Resetting Administrative Password without startup disk
Away from my home, attempting to access Macbook Pro administrative settings. Forgot password and unable to gain access without my startup disk. Wondering if there is a way around this or a way to reset password.
-
HT4623 Why aM i UNABLE TO CONNECT TO at&t TO ORDER CELL SERVICE?
Please advise how I can connect to AT& T to order cellular service?