Package to jar in eclipse

11,481

Solution 1

@trideceth12 I just tested exporting a sample package in my eclipse. and my folder structure works fine. not sure why yours is not working properly. you should check all your export settings. here's what mine looks like, and it exports fine.enter image description here

Solution 2

when you create jar file using eclipse choose the export option ,in your jar creation wizard chosse your necessary folder ,then finish, for see here

Solution 3

Look like your Java source is in Default package only. If you want to use this kind of import statement, considering moving the jar file to:

pkg/nme/with/dots
Share:
11,481
jsj
Author by

jsj

Updated on June 13, 2022

Comments

  • jsj
    jsj almost 2 years

    UPDATE: Don't worry. User Error. Would delete the question but cant with answers.

    I am trying to use eclipse to create a jar of packages, not a runnable jar, which I can import into another project.

    So far I have done this:

    1. Create a new project
    2. Create a package in that project (pkg.nme.with.dots)
    3. Create a class in that package
    4. Export -> Java -> Jar

    The resultant .jar file has only one directory META-INF, and three files .project, .classpath, and MyClass.class.

    If I try to import pkg.nme.with.dots.MyClass; I get a package not found error, despite adding the full path of the jar to my CLASSPATH.

    I tried adding the jar as an external lib in eclipse but it is still not recognised.

    Obviously I have exported it into a format that can't be imported. How do I export it correctly?