tags:

views:

960

answers:

5

I'm tasked with converting an existing Java/C++ mixed web-application to pure Java, but I'm hampered by some missing Java sources (.java files) for which only the class-files are available. Fortunately I don't need to change anything in that code, just need to continue calling the methods.

I created a new Java Web Application project (using Netbeans); recreated the applet by copying it's sources in and got it working in a skeletal fashion, with the calls to classes & methods not in the sources commented out, but I am now stuck on how to add the class-files (of the missing sources) to this project.

(I'm new to Java, obviously) Any pointers on how I should proceed will be most welcome.

+2  A: 

To add some source/code to your project, classic java project or webapp java project, you have to declare the path to the needed class/jar in the classpath variable.

If you are running your dynamic web project via eclipse, just add the path to the classpath tab in the "run configurations" of your server.

To learn more about classpath, see wikipedia.

enguerran
+2  A: 

Package the .class files in a jar.

$ jar cvf my-library.jar  the/package/*.class

Add this jar to the CLASSPATH of your project/application. In Netbeans:

  • go to the project view on your left
  • then right click on the library option,
  • then click add JAR/Folder option.
Pascal Thivent
Okay - works now (I made a silly mistake first time I tried it) - thanks.
slashmais
A: 

The usual approach is to collect all these class files in a JAR file (use the jar tool) and put them on the classpath.

Aaron Digulla
A: 

Different from C/C++, for Java you don't need the source code to these other pieces in order to compile the applet. There is enough information in the class file for the Java compiler to do what needs to be done.

So you can uncomment the calls to this code and follow the instructions in the other posts to put the class files on your project classpath.

A: 

In the Project window, right click on your project and select Properties. Go to the Libraries category. Then click Add JAR/Folder and select the location of your .class files.

OliBlogger