Adding a .class file to your Java project.

All I can say is Java class paths are a real pain in the butt. Recently I developed a Java Swing application using the JTwain library. The company I purchased the library from uses a .class file as their license. The only instructions were to put this file in your class path. It sounded simple enough but this was the first time I have ran across this and was unsure the correct way to get the class file in my project. After several failed attempts and many trips to “The Googles” I came up with the following solution. It is pretty simple and works great. I am using Netbeans IDE but the same concepts should be the same for Eclipse, JDeveloper, etc…

  • Create a new project. In Netbeans you want to create a Java Class Library project.

screenhunter_02-2009-06-17

screenhunter_04-2009-06-17

  • Next you want to copy your .class file into the src directory of your project.
screenhunter_09-2009-06-17

Windows File Explorer - Projects src directory

screenhunter_08-2009-06-17

Netbeans Project Explorer

  • Once you have the .class files in your src directory you can right click on your project select Clean and Build.

screenhunter_07-2009-06-17

  • After you build the project you should see the jar file in your projects dist directory. You can simply add this jar file to your project just like any other jar file and it will automatically be in the class path.
screenhunter_10-2009-06-17

Windows File Explorer - Projects dist directory



Comments

  1. Hyde June 30th

    Comment Arrow

    Hi… I am having trouble including the JTwainLicense.class into the classpath. I followed your way by creating a jar but didnt work. I am doing all this in the RAD. So thought of running the JTwain standalone as a java project but still didnt work. Is there a other way around.


  2. Brian June 30th

    Comment Arrow

    You should be able to just add the jar into your project just like any other jar file. What IDE are you using and what error are you getting?


  3. Nishad K A October 19th

    Comment Arrow

    Hi, I do had the same license problem, but it’s almost resolved with the technique you specified, and thanks for that.
    But while scanning using this, each time I have to kill the java.exe32 process, else the system will hang up.
    Is this due to any incomplete installation of the license or any other problem??
    Any remedies for that??
    Thanks in advance…


Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Brian

Brian Abston is a Java Developer in Oklahoma who also loves technology.