Results 1 to 5 of 5
Thread: Importing a custom library
- 02-20-2013, 03:29 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
How do I import a custom library?
I put my program in
I am using HTMLUnit and put the jar in the same folderJava Code:C:\Users\Documents\Java Programs\MyProgram.java
I want my program to use the htmlunit libraries without having to put it inside the jar. How do I do this?Java Code:C:\Users\Documents\Java Programs\htmlunit.jar
The only thing that felt like progress so far was doing this in the command prompt
The WebClient part is a class in the library. The only reason I have it there is because it's the only thing that gave me a different result. I could replace it with another class in the library I'm sure and get the same error.Java Code:java -cp "C:\Users\Documents\Java Programs\htmlunit.jar" com.gargoylesoftware.htmlunit.WebClient
But then it tells me I need a main method in this folder in order to set the class path. That doesn't make sense to me because why would a library have a main method?
That's what my program is for. Isn't the classpath a location that the compiler will check for libraries? I know some of you may say you can just do
But when I use the WebClient class, it saysJava Code:import htmlunit.com.gargoylesoftware.htmlunit.*;
Can someone please give me a guide on this?Java Code:C:\Users\Documents\Java Programs\Testing.java:14: error: cannot access WebClient WebClient webClient = new WebClient(); ^ bad class file: .\htmlunit\com\gargoylesoftware\htmlunit\WebClient.class class file contains wrong class: com.gargoylesoftware.htmlunit.WebClient Please remove or make sure it appears in the correct subdirectory of the classpath. 1 error Tool completed with exit code 1Last edited by chrondog; 02-20-2013 at 04:20 PM.
- 02-20-2013, 10:22 PM #2
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Re: Importing a custom library
Was my post hard to understand? I'll restate what I asked in different words.
I have a package I downloaded named htmlunit.jar.
How can I import the classes in htmlunit.jar just like I can do "import java.awt.*;"?
Just like I can link the standard SDK to any of my programs, I want to link htmlunit so I can use it.
EDIT: I got it working with the NetBeans IDE. But still, I'd like to know how it is done manually.Last edited by chrondog; 02-20-2013 at 10:46 PM.
-
Re: Importing a custom library
You mention you've put your java file somewhere, but where do you have your *class* files? Have you compiled your project yet into class files?
- 02-20-2013, 11:21 PM #4
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Re: Importing a custom library
I was using TextPad which doesn't have "projects"; just a java file and the compiled class file. So yea I do have it compiled.
- 02-21-2013, 09:38 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Importing a custom library
Just import it in your class.
When you compile your class you need to include the jar file that has those classes in your classpath (-cp), and also when you run your class file.
Thos are its dependencies...the 3rd party things your code needs in order to run.Please do not ask for code as refusal often offends.
Similar Threads
-
Importing a web library
By Boreeas in forum New To JavaReplies: 9Last Post: 04-24-2011, 03:09 AM -
Importing a cvs library
By malaguena in forum New To JavaReplies: 2Last Post: 03-14-2011, 11:48 PM -
importing a library into my program
By sniffer139 in forum NetBeansReplies: 1Last Post: 03-22-2010, 01:29 PM -
Importing custom class
By BigRed in forum EclipseReplies: 2Last Post: 02-14-2009, 02:12 PM -
Importing a Custom Class
By jfredrickson in forum New To JavaReplies: 3Last Post: 07-11-2007, 11:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks