2

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.

5 Answers 5

7

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.
Sign up to request clarification or add additional context in comments.

1 Comment

Okay - works now (I made a silly mistake first time I tried it) - thanks.
2

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.

Comments

0

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

Comments

0

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.

Comments

0

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.

1 Comment

.class files are not selectable here using NB 7.1.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.