Solved

how do i access a class in a library jar file?

Posted on 2008-10-25
8
304 Views
Last Modified: 2013-12-14
I have attached a jar file to my new project. The jar file has a bunch of classes in the default package. So, the one i want to instatiate is named AgentImpl.

When i go to create an AgentImpl agent = new AgentImpl(); it does not see the class.

How do i access these classes inside of the jar file.

I can see the jar file under my libraries in netbeans, so i attached it correctly.

thanks
0
Comment
Question by:alexmac05
  • 5
  • 3
8 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22805732
I believe the problem is the fact that the classes are in the default package.  If the JAR is your own from another project, name the package and see how that works.  If not, I will try to find how as I haven't had to work around this much as usually JAR's have package names for public interface/classes that I have worked with.
0
 

Author Comment

by:alexmac05
ID: 22805742
It is my own so I will try to name the package and see if that works. I'll let you know shortly.

Thanks!

alex
0
 

Author Comment

by:alexmac05
ID: 22805782
OK.

I have three projects total in netbeans. The first two need to see each other via package and the third needs to interact with a jar file from EDMS_Agent.

1) EDMS_Agent
all classes are now in package agentpackage

2) ElectionLibrary
all classes are now in package electionpackage

How do I import the packages to the different projects?

I did create a jar file of the EDMS_Agent but now that I changed the package of that jar I can not build it because the ElectionLibrary (which needs to see some classes in EDMS_Agent and visa versa) - they can't see each other so I can't build them. So, i need to get those two packages seeing each other so that I can rebuild the jar to attach it to my third project named ManagementStudioApplication.
0
 

Author Comment

by:alexmac05
ID: 22805814
How do I access code from project to project in netbeans?

Does a project need a jar file in order to see classes from another project?

If you know the answer then please let me know.

Otherwise, I was able to move the code from ElectionLibrary into EDMS_Agent and then put it all under one project and then create the jar file and then it worked.

THANKS!!!!

alex

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Closing Comment

by:alexmac05
ID: 31510026
Just wondering - in netbeans if I want classes in one project to access classes in another project - does it have to be through a jar file?  I can't access the namespace through importing the package?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22805847
If you right-click on the project and select properties, you can click on Libraries (same place you would add JAR) and click on the Add Project button.  This will let you build your current project with visibility to the classes in the other project(s).

Hope that helps.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22805850
Once the projects are linked in the classpath, you import them like you would normally.

import electionpackage.*;
0
 

Author Comment

by:alexmac05
ID: 22807816
yes, thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now