Jump to content


Working With Jar Files


  • Please log in to reply
10 replies to this topic

#1 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 21 March 2005 - 10:51 PM

I'm trying to create a JAR file that I can then import into other projects.  I know how to create the JAR file, but then when I go to import it into another project it doesn't find it.

Am I missing something?

#2 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 21 March 2005 - 11:04 PM

QUOTE(mglanfield @ Mar 21 2005, 11:51 PM)
I'm trying to create a JAR file that I can then import into other projects.  I know how to create the JAR file, but then when I go to import it into another project it doesn't find it.

Am I missing something?

View Post


you should set it as a required library
Project > Project properties > Required libraries > New
make up a name, click add > archive
then find your jar, click OK.

select it in the required libs tab you now see, click OK

and you're set :)

edit: I think I missed an OK somewhere in this post... mm.. you'll find it out I'll guess :)
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#3 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 22 March 2005 - 11:31 AM

Perfect!  I'll try that out.

Thanks for your help!


#4 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 22 March 2005 - 04:55 PM

Ok, that works.  However, now it's giving me the error:

RoboRace.jar(CardFactory.java):3: class CardFactory is public, should be declared in a file named CardFactory.java
(source unavailable)

The class CardFactory is public, but I didn't think that would an issue.  How could it expect it to be in its own file if it's compacted into a JAR file?

To explain, CardFactory is one of many public classes included in the package RoboRace.

Any ideas?

#5 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 22 March 2005 - 05:02 PM

actually, I have never been able to compile a project when it gives me that error.. only way I know to solve this is to put it in it's own *.java file.

It should not be an issue however if you have multiple public classes in a Jar file, I have done that before many times and it was never a problem..

btw, you are using your compiled *.class files in the .jar instead of the *.java files you may have? (I presume you are, but little checking doesn't hurt anybody)
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#6 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 22 March 2005 - 05:05 PM

I think I am.  Should I be in order for this to work?

To clarify:  I need to use the .class files, NOT the .java files, is this correct?

#7 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 22 March 2005 - 05:08 PM

QUOTE(mglanfield @ Mar 22 2005, 06:05 PM)
I think I am.  Should I be in order for this to work?

To clarify:  I need to use the .class files, NOT the .java files, is this correct?

View Post


yes
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#8 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 22 March 2005 - 05:12 PM

Sorry to keep asking questions, but how do I choose to use the .class files instead?  When I click on the tool Create JAR file it just creates it by adding all classes in the project.

#9 mglanfield

mglanfield

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 22 March 2005 - 05:14 PM

Actually, I figured it out.  I was missing the "package RoboRace" in the new project.

Thanks for all your help!

#10 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 22 March 2005 - 05:41 PM

QUOTE(mglanfield @ Mar 22 2005, 06:12 PM)
Sorry to keep asking questions, but how do I choose to use the .class files instead?  When I click on the tool Create JAR file it just creates it by adding all classes in the project.

View Post


make sure that you have JC set up to use another directory for class files than for source files, then in the tool options, set the initial directory to: "$[OutputPath]"

QUOTE(mglanfield @ Mar 22 2005, 06:14 PM)
Actually, I figured it out. I was missing the "package RoboRace" in the new project.

Thanks for all your help!

:)
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#11 lordSauron

lordSauron

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts
  • Gender:Male
  • Location:California, United States
  • Interests:Dominating Middle-earth, enslaving all the free peoples and keeping my Silmaril stones nice and shiny.

Posted 23 March 2005 - 09:18 PM

So you use the .class files... That could explain why jar.exe ate my source code....  Oops.  Had to remake an entire file (luckily it only changed one source file into unreadable byte code.  It could have been much worse...)
Lord Sauron the Great
lordSaurontheGreat@gmail.com
JDK 6 Documentation - READ IT!  LOVE IT!  LIVE IT!
THOU SHALT GOOGLE BEFORE POSING THY QUERY!
If you're reading this you have given me control of your mind.
Why do accesses to your mind throw a "null pointer exception?"