Highlighted
Absent Member.
Absent Member.
8736 views

Cobol JVM Example - Classpath

Jump to solution

[Migrated content. Thread originally posted on 17 February 2011]

Hello,

is there a way to add libraries to the classpath in Eclipse.
I have a class in a .jar file (code below) :

package com.easypaygroup.javacobol;

public class Content {

private String content = "Initial value";

public void showContent(){
System.out.println(content);
}
public static void main(String[] args) {
Content content = new Content();
content.showContent();

}

}

And i have a COBOL JVM project with the following source :

program-id. testjava as "testjava".
environment division.
configuration section.
data division.
working-storage section.

procedure division.
invoke type java.lang.System::out::println("help")
invoke type
com.easypaygroup.javacobol.Content::showContent().

goback.

end program testjava.

I do not get it compiled in Eclipse. Adding the jar library to the classpath in Eclipse doesn't help.
Do i need to modify the ant build file ?

Regards,

Renzo
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
I've just tested this out....

set an addition directive on your cobol compilation - JVMCLASSPATH(c:\content.jar) - replace my exmaple path with your real one and it will work - though the declaration of the showContent method needs to be static to match the way you're calling it in the cobol.

What was previously suggested should have worked, and Alex says we'll be looking to address that in the next release.

View solution in original post

0 Likes
17 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol JVM Example - Classpath

Jump to solution
You should be able to add jar files to the COBOL JVM project by right clicking on the project name and selecting Properties.

Highlight Java Build Path and select the tab for Libraries.

You can then click Add Jars... or Add External Jars... in order to make the jar file visible to your project.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
Hi Chris,

that is the way it should work, but it doesn't.
When compiling the cobol source, the classpath from the Java Build Path isn't taken in account.

I have tried it with a .jar archive and with a class folder, but i always get
COBCH0845S Unknown class 'com.easypaygroup.javacobol.Content'

Are there samples available of Eclipse projects with Cobol JVM that do this ?

Regards,

Renzo
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
Hi,

We are looking into a work around for you right now. This is a know issue which is being fixed for the full release; for now I am sure we can get you up and going again.

Best wishes - AJ
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
I've just tested this out....

set an addition directive on your cobol compilation - JVMCLASSPATH(c:\content.jar) - replace my exmaple path with your real one and it will work - though the declaration of the showContent method needs to be static to match the way you're calling it in the cobol.

What was previously suggested should have worked, and Alex says we'll be looking to address that in the next release.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
Hi Chris,

Eureka, it works !

What do you mean with "though the declaration of the showContent method needs to be static to match the way you're calling it in the cobol" ?

Is there another way in cobol than the "invoke type" command, so that i don't have to use static methods ?

Regards,

Renzo
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol JVM Example - Classpath

Jump to solution
You can use the New method to create an instance of a class and store it in a data item.
You can then call the instance methods within that object.

01 lsTestInstance   type   TestClass.

   set lsTestInstance to new type TestClass
   invoke lsTestInstance::myMethod()
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution
Thanks,

small step for man, giant leap for (RM/Cobol) mankind.

Regards,

Renzo
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution

.....and Alex says we'll be looking to address that in the next release.....Could you please say to me what new Release will be this ???

PJM

Pedro Juan Montero Bernales

PJM Informatica Soluciones Globales

Santiago - Chile

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol JVM Example - Classpath

Jump to solution

This post was from several years ago and this particular problem has been addressed back then and should no longer occur with any current release.

Are you still experiencing a problem in this area?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Cobol JVM Example - Classpath

Jump to solution

YES, I replicated the example  :

package javacobol;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

public class Javacobol main {

private String content = "Initial value";

public static void main showContent(){

System.out.println(content);

public static void main(String[] args) {

Content content = new Content();

content.showContent();

}

}

And get the same problema.....I am using the versión of Visual Cobol enclosed.

 

TKS

 

 

 

 

 

PJM

Pedro Juan Montero Bernales

PJM Informatica Soluciones Globales

Santiago - Chile

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol JVM Example - Classpath

Jump to solution

I am not sure I understand what it is that you are trying to do here...

In the original post, the user was trying to invoke a method in a Java class from a COBOL main program.

What was fixed was that you can now add the .jar file containing the java class to the COBOL project build and it will pick up the class reference correctly.

In your java example, which appears to be invalid, you are defining a main entry point which means that this java program would be the main program and not the COBOL.

Can you show me the COBOL code that you are using and provide detail on what you are attempting to do?

Thanks.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.