views:

293

answers:

3

Hi,

What i need to do is as follows:

  1. I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated.

  2. I want to use this .class file from a .java file. That is, i need to import this(.class) file as i want to use some functions defined in the scheme file which is now a .class file.

  3. How do i do it in Eclipse? i have created two packages one for java and one for the .class file. Then i import the package containing the .class file. But i am not able to use the function in the .class file in the .java file. Are there any settings to be done?

Please let me know how this can be done.

+4  A: 

You can add a folder containing compiled classes to your project by right clicking the project, then select Properties > Java build path, then "Add External Class Folder"

Or choose "Add Class Folder" if you have copied the class files into a sub directory of your project.

This will add the class files to the projects classpath and you can then import the class into your java file using an import statement:

import my.package.MyClass;

Note: The package structure should be maintained under the folder that you add as a class folder. So if you add folder "myclasses" as a class folder, the directory structure should be as follows for the example above:

myclasses/my/package/MyClass.class

Neal Donnan
+1  A: 

You could create a jar out of it and add it as a library -- jars are typically packaged with just the .class files. Just jam them into a .zip file with the correct filesystem (unzip another .jar to have a look inside) and rename to .jar. You could also use the official jar tool -- e.g., jar cvf TicTacToe.jar TicTacToe.class

http://java.sun.com/docs/books/tutorial/deployment/jar/build.html

alt text

Chris Dennett
A: 

Hi, thanks for the reply.. Now there is no problem in importing the package containing the .class files. But i am not able to run my application as a Java application. It gives me an error of the following kind

java.lang.NoClassDefFoundError: com/test/java/Test Caused by: java.lang.ClassNotFoundException: com.test.java.Test 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) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Exception in thread "main"

this is happening even though the java/Test.java has a main method in it.. Please let me know in case you have any ideas regarding the solution for this problem.

Namratha Nayak
hi, my problem has been solved. It was related to the package structure of the .class files i was using.
Namratha