satya kiran

Ranch Hand
+ Follow
since Nov 07, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by satya kiran

I placed couple of options.

1. provided the -Djava.library.path=\\the directory of the dll
2. placed the dll path in the Windows Environment variable PATH%.

When i googled in the web, what i understood from the error message, it is finding the dll, but could not locate the corresponding method. Correct me if my understanding is incorrect.

Am i missing anything vital here?

Thanks in advance for your help.

Kiran
14 years ago
Hi,

I've created the dll file and loading that from the Controller class by calling the system.loadLibrary("test.dll");
The JNI Functionality is working fine if the caller is a standalone java application.

For Web applications, i am getting UnsatisfiedLink Error.

Why is it not working in WebApplications where as working in Standard Java Applications? Do i need to do any changes? The same result holds for different web applications i tried (servlets, struts). Any Help is highly appreciated.




Here is what i am trying to do:

TestController.groovy



Test.java



I am getting below error:

org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.UnsatisfiedLinkError: Test.create()J

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1062)




Thanks,
Kiran

[NK: UseCodeTags]
14 years ago
Hi,

I've created the dll file and loading that from the Controller class by calling the system.loadLibrary("test.dll"); The same class is working fine if i create a standalone java application.

When executed, i am getting UnsatisfiedLink Error. I've the below questions.

1. Where should i set the -Djava option so that grails looks at the correct location for the dll.
2. If my controller has package name and the java class that has the native calls does not contain any package name, is it going to be of any issue?
3. Any other suggestions.


Here is what i am trying to do:

TestController.groovy

package com.abc.test.control;

class TestController {

static {
System.loadLibrary("libABCILib");
}

def validateJni ={

Test test = new Test() // Java class that has jni calls
test.create();
}

}

Test.java

public class Test {

// used to hold the C++ object pointer
private long Tesetobj;

// create native object
private native long create();

public Test() {
Testobj = create();

}

}



I am getting below error:

org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.UnsatisfiedLinkError: Test.create()J

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1062)


Thanks in advance for your help.

Regards,


14 years ago
How can i refer a framework jar in a grails application ( I tried from command line and placed the jar in the lib folder. But still getting the class not found exception). I tried to modify the Ivy.xml with no luck. I couldn't locate any links on this. Any help/suggestions/links will be highly appreciated.

Thanks,
14 years ago
Thank you Gregg. But If i open a grails project in netbeans i dont see any options to set the classpath ( for other projects such as java, j2ee etc., i can set the classpath). I googled with no luck.


Regards,
Kiran
14 years ago
Hi,

I am new to Groovy/Grails and bear with me for this basic question. I am using netbeans 6.7 IDE. Grails 1.1. I've Included xxxframework.jar(jar file has java classes) in the Grails application/lib folder. When i try to import the java class, i am getting classnotfound exception. If i enter the package name and hit ctrl+space it is showing the classes in the jar, but when i finish the import statement i.e., import com.trail.xxx.xx.classname it is giving me classname not defined (even compile giving me errors). Am i doing something wrong or missing any thing vital? Is there any way i can exlusively set the classpath in netbeans for the Grails Application?

Thanks in advance for your help

Thanks,
kiran
14 years ago
Thank you Very much Guys. Now i am clear on this.
Thank you Derby. The link is of more help.
What is the output of the following class? Is the result because
strings are immutable or pass by value/reference?? Please explain (i always get confused with this question)

public class Bar {
private static String a;
private static void foo(String a){
a = "second";
}
public static void main(String[] argv){
a = "first";
System.out.println(a);
foo(a);
System.out.println(a);
}
}
Thank you Jeanne.

So, will it work if i change the call to the method mainLogic in
synchronize block.

i.e., synchronize {
mainLogic()
}

(or) what other ways i can eliminate this problem.

Please clarify,

Thanks in advance for your help

Regards,
Satya

Many thanks for you
Thank you. Your explanation is very helpful for me to understand the result.
Hi,

I want to know what will be the out put and why it is so?

public class Merry {

static void doHelloGoodbye(Base b){
b.greeting();
b.farewell();
}

public static void main(String args[]){
Sub s = new Sub();
doHelloGoodbye(s);
}
}


class Base{
static void greeting(){
System.out.println("Hello");
}
void farewell(){
System.out.println("Goodbye");
}
}

class Sub extends Base{
static void greeting(){
System.out.println("Hi");
}
void farewell(){
System.out.println("See ya!");
}
}

Thanks in advance.
Hi,

The following code is a sample application, which accesses a shared SQL database. This code seemed ok in test but causes some unrelated updates of salary to be occasionally lost in production. Why could this happen? What options are there to resolve this problem? Your suggestions will help me alot.

Thanks in advance.



import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class Operation {
private Connection c;

private void mainLogic(long empId) throws SQLException {
BigDecimal salary = selectSalary(empId);
salary = indexSalary(salary);
updateSalary(empId, salary);
}

public void execute(Connection aConn, long empId)
throws SQLException {
c = aConn;
c.setAutoCommit(false);
try {
mainLogic(empId);
c.commit();
} catch (SQLException e) {
c.rollback();
throw e;
}
}

private BigDecimal selectSalary(long empId) throws SQLException {
PreparedStatement ps = c.prepareStatement(
"SELECT salary FROM emp WHERE emp_id = ?");
ResultSet rs = null;
try {
ps.setLong(1, empId);
rs = ps.executeQuery();
rs.next();
return rs.getBigDecimal("salary");
} finally {
if (rs != null) {
rs.close();
}
ps.close();
}
}

private BigDecimal indexSalary(BigDecimal salary) {
return salary.multiply(new BigDecimal("1.1"));
}

private void updateSalary(long empId, BigDecimal salary)
throws SQLException {
PreparedStatement ps = c.prepareStatement(
"UPDATE emp SET salary = ? WHERE emp_id = ?");
try {
ps.setBigDecimal(1, salary);
ps.setLong(2, empId);
ps.executeUpdate();
} finally {
ps.close();
}
}

public static void main(String args[]) throws Exception {
Class.forName(args[0]);
Connection c = DriverManager.getConnection(args[1], args[2], args[3]);

Operation op = new Operation();
op.execute(c, Long.parseLong(args[4]));
}
}

Sample DDL is for emp is:

CREATE TABLE emp ( emp_id NUMERIC PRIMARY KEY,
salary NUMERIC NOT NULL);
Hi Peter,

Thanks for your post. I Verified the ports and 9080 is present in the list. Do i need to verify any other place?
19 years ago