• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling a java class from COBOL

 
Greenhorn
Posts: 13
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am fairly new to COBOL, I am a JAVA developer but I have been tasked with calling a java program from an existing cobol program.

So I thought I'd start with a basic proof of concept to see how it works and I can't even get it to load basic java libraries.

here is my cobol program :

$set ooctrl "+p-f"

program-id. Hello as "Hello".

environment division.

configuration section.

class-control.

JHello is class "$JAVA$com.ice.cobol.Hello"

JString is class "$JAVA$java.lang.String"

.

data division.

working-storage section.

01 jstring2 object reference JString.

01 javaMethod object reference.

01 W005-MESSAGE-FIELD PIC X(32).

procedure division.

DISPLAY-ACCEPTED-MESSAGE.

ACCEPT W005-MESSAGE-FIELD.

DISPLAY "HELLO WORLD........" W005-MESSAGE-FIELD LINE 2

POSITION 10.

invoke JHello "new" returning javaMethod .

invoke javaMethod "getValue" returning jstring2.

display " Return Value : " jstring2 LINE 5 POSITION 10.

STOP RUN.

end program Hello.

java code is :

package com.ice.cobol;

public class Hello {

public Hello(){

}

public String getValue(){

String result = " Hello World!!!";

return result;

}

}

Enviroment varialbes details :

CLASSPATH = C:\Users\Admin\Desktop\Sample\folder (put here on my java class)

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_25

COBDIR = C:\Program Files (x86)\Micro Focus\Visual COBOL

Path = %JAVA_HOME%\bin;%COBDIR%\bin64;%CLASSPATH%;C:\Program Files\Java\jre7\bin\server\;

And my Error:

Exception 65538 not trapped by the class javaexceptionmanager.

Description: "Java runtime exception"

Unable to load class: com.ice.cobol.Hello

Hit T to terminate program. Hit any other key to continue.

Please help me.
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Description: "Java runtime exception"

Unable to load class: com.ice.cobol.Hello




Did you supply this class? Where is it located? It should be placed according to the package structure.
 
Chaitanya ekre
Greenhorn
Posts: 13
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ivan
I really appreciate the quick response.
But i am not getting what exactly do you mean by providing class in project structure.

The java class and cobol program are in different projects.
To access java class from cobol program i have defined this java class in environment variable as described in the first post.
but i dont know doing this is correct or not.

So can you please elaborate the solution ??

Thanks in advance !!
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does C:\Users\Admin\Desktop\Sample\folder contain a file called Hello.class or does it contain a directory structure that matches the package name of your class with the Hello.class file in the lowest directory ?
 
Chaitanya ekre
Greenhorn
Posts: 13
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have checked it both ways that is
1. classpath = C:\Users\Admin\Desktop\Sample\folder\hello.jar
2. classpath = C:\Users\Admin\Desktop\Sample\folder

JAVA_HOME = C:\program files(x86)\java\jdk1.7.0_21
COBDIR =C:\program files(x86)\microfocus\visual COBOL
COBJVM = SUN


path = %JAVA_HOME%\bin;%classpath%;%COBDIR%\bin;C:\program files(x86)\java\jdk1.7.0_21\jre\bin\server\jvm.dll;%COBJVM%

one more thing when i am using java.lang.String it is working fine but when i am trying to add my java class its not working.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chaitanya ekre wrote:i have checked it both ways that is
1. classpath = C:\Users\Admin\Desktop\Sample\folder\hello.jar
2. classpath = C:\Users\Admin\Desktop\Sample\folder


Well actually, I didn't mention either of those ways.
So now the question becomes, does hello.jar exist in that directory and does it (the jar file) contain Hello.class in the correct directory structure ?
 
Chaitanya ekre
Greenhorn
Posts: 13
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the jar exits in that directory structure and it has hello.class file.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chaitanya ekre wrote:Yes the jar exits in that directory structure and it has hello.class file.


And the Hello.class (I assume the lowercase 'h' in your post was a typo) is in a directory called com/ice/cobol and the com directory is at the top level of the jar ?

If that is all correct then I can only guess that Cobol doesn't use the CLASSPATH environment variable and you need to set it some other way, but I don't know what way that would be as I've never used java from within Cobol.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic