Absent Member.
Absent Member.
2277 views

Using a java class from a COBOL JVM project

Jump to solution

[Migrated content. Thread originally posted on 15 July 2011]

Hello,

I want to use a java public class from a COBOL JVM project. The program I use in order to do this is named "Program1.cbl". Here you can see how simple it is:

program-id. Program1 as "Program1".

data division.
working-storage section.
77 cPantalla type pantalla.
77 text1 pic x(10).

procedure division.

display "Hello, I am Program1!".

set cPantalla to new type pantalla.
invoke cPantalla:open().


goback.

end program Program1.

In Properties->Java build path->Libraries I have included the runnable jar generated from the Java project. The jar file is stored at c:\.

The IDE does not recognize the type "pantalla" presumably populated by the java package. And the following error occurs:

java.lang.NoClassDefFoundError: Program1
Caused by: java.lang.ClassNotFoundException: Program1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"

Any ideas? What the heck am I doing wrong? Do you need the sample code?

Regards
0 Likes
1 Solution

Accepted Solutions
Absent Member.
Absent Member.
Hi Miguel

The Java project you've uploaded doesn't compile (lots of hardcoded paths to jars on your machine), but I can see a couple of issues. The first is, you need to put your fproc_JavaSWT project on the build path of your COBOL project. You can do that by bringing up the properties for your COBOL project, selecting Java Build Path and selecting it on the project tab. Including the jar output from the Java project (which you said you did) is an alternative. The next issue is that your class, pantalla, is in the package fproc_JavaSWT.

So its full type name is fproc_JavaSWT.pantalla . So for example:

77 cPantalla type fproc_JavaSWT.pantalla.

set cPantalla to new proc_JavaSWT.pantalla

Alternatively, you can set the ilusing directive to import the namespace into your project. Go to the project properties again, and add ilusing(fproc_JavaSWT) to the additional directives field. If you add the directive, you don't need to qualify every reference to pantalla with its package name.

If you haven't done a lot of Java programming, it might be worth familiarizing yourself with packages and how they work in the JVM world - you could do worse than start here:

http://download.oracle.com/javase/tutorial/java/package/packages.html



View solution in original post

0 Likes
8 Replies
Micro Focus Expert
Micro Focus Expert
Can you please zip up your sample project including the .jar file that you are trying to use and attach it to your reply?

Thanks.
0 Likes
Absent Member.
Absent Member.
The likeliest thing is that you have not put your current directory on the Java classpath. From whichever directory contains Program1.class, try this:

java -cp . Program1

that puts your current directory on the classpath, and then the JVM will find your class files.
0 Likes
Absent Member.
Absent Member.
Chris Glazier originally wrote:
Can you please zip up your sample project including the .jar file that you are trying to use and attach it to your reply?

Thanks.


Hello Chris,

I don't know how I can attach the project in a message here. Could you please give me your e-mail address?

Thank you
0 Likes
Absent Member.
Absent Member.
You can write me to miguel.ossa@mango.com
0 Likes
Absent Member.
Absent Member.
Paul Kelly originally wrote:
The likeliest thing is that you have not put your current directory on the Java classpath. From whichever directory contains Program1.class, try this:

java -cp . Program1

that puts your current directory on the classpath, and then the JVM will find your class files.


Program1.class does not exist because compilation fails! I don't know how to handle this; it is a COBOL program.
0 Likes
Absent Member.
Absent Member.
Hello,

I have uploaded the project to Fetch.IO.

Here is the link: Project on Fetch.IO

Regards
0 Likes
Absent Member.
Absent Member.
Hi Miguel

The Java project you've uploaded doesn't compile (lots of hardcoded paths to jars on your machine), but I can see a couple of issues. The first is, you need to put your fproc_JavaSWT project on the build path of your COBOL project. You can do that by bringing up the properties for your COBOL project, selecting Java Build Path and selecting it on the project tab. Including the jar output from the Java project (which you said you did) is an alternative. The next issue is that your class, pantalla, is in the package fproc_JavaSWT.

So its full type name is fproc_JavaSWT.pantalla . So for example:

77 cPantalla type fproc_JavaSWT.pantalla.

set cPantalla to new proc_JavaSWT.pantalla

Alternatively, you can set the ilusing directive to import the namespace into your project. Go to the project properties again, and add ilusing(fproc_JavaSWT) to the additional directives field. If you add the directive, you don't need to qualify every reference to pantalla with its package name.

If you haven't done a lot of Java programming, it might be worth familiarizing yourself with packages and how they work in the JVM world - you could do worse than start here:

http://download.oracle.com/javase/tutorial/java/package/packages.html



View solution in original post

0 Likes
Absent Member.
Absent Member.
Thank you. I was not able to solve the problem using the steps you described. I finally found that there were errors in previous layers of the project that were masked inside the jar. In order to resolve this issue, I used a previous version of the program and then I gradually copied & pasted the new code into the diferent sources. Then, errors related with the scope of several variables appeared. Solved this, the program begun working correctly.

A bit messing. Perhaps these problems have anything to see with Eclipse IDE.

Regards
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.