Reputation: 691
I have just created my first JAR in Eclipse, just a simple program with a single class Database.class. It is not in a package.
public class Database {
public Database() {
int dbInit = 1; } }
I have added it as an external JAR to the build path libraries for another project in Eclipse, but for some reason I cannot get Database db = new Database()
, the default constructor, to work - it's as if the contents of the JAR are not being recognised.
Could anyone please offer any advice on this?
Thanks very much,
M
Upvotes: 0
Views: 925
Reputation: 115328
jar vft myjar.jar
You should get output like
Database.class
Check that it is exactly what you get. Your class file must be at the root of the jar.
Verify that you are adding it to your second project correctly: Project/Properties/Java Build Path/Libraries, push button "Add external jars...", navigate to the jar and add it.
Now try to write in any java class of your project: Datab then push ctrl/space It should complete to Database. Continue coding and enjoy.
BTW: why did you put your class to default package? I'd suggest you to put it into package. It will help you to avoid mistakes. for example probably you have other class named database in your code. How are you planning to resolve this conflict?
Upvotes: 2
Reputation: 55907
The build path is not used at runtime. In your run configuration there's a tab to allow you to specify the classpath used when running the app.
Upvotes: 0