Results 1 to 8 of 8
  1. #1
    turboscrew is offline Member
    Join Date
    May 2011
    Location
    Nokia, Finland
    Posts
    22
    Rep Power
    0

    Default java program and libraries

    Is there a way to include library stuff in the java program so that copying the program
    is enough for running the program, or do I need to install all the libraries to each machine
    where that (small) program is to be run?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: java program and libraries

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: java program and libraries

    If your program depends on 3rd party (ie non-core) Java packages, then it is not small, because it relies on these other packages.

    And you don't install them. They just have to be deployed along with your stuff.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    turboscrew is offline Member
    Join Date
    May 2011
    Location
    Nokia, Finland
    Posts
    22
    Rep Power
    0

    Default Re: java program and libraries

    There are a couple of 3rd-party .jar-libraries containing a couple of packages each.
    There are also a couple of .dll-libraries. those are (probably) needed too?
    (They could be used from within the .jar-libraries?)

    How should I tell java where to find them if I run the program from command line (or script file)?
    I created a variable "CLASSPATH" to both cygwin and windows environment variables, but I keep getting
    "NoClassDefFound"-errors about the classes used from the .jar-libraries.
    Last edited by turboscrew; 04-18-2013 at 01:47 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: java program and libraries

    Don't add CLASSPATH at a system level.
    It is only needed when you run the code.
    If your code is in an executable jar file then the classpath is part of the manifest.

    As for what's needed for the jar files you're including, you'll need to read up on their documentation and find out.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    turboscrew is offline Member
    Join Date
    May 2011
    Location
    Nokia, Finland
    Posts
    22
    Rep Power
    0

    Default Re: java program and libraries

    Boy, are you fast responders... :-)

    I guess I'll better take all the files - at least the .jar files, but how?

    I have a directory with the .jar-files - say, C:\3rdparty\scripting\java where the .jar-libraries are found by default.

    How do I tell java to find the library classes for a java program - say, C:\my_appl\tools\my_program.jar that uses them?

    I tried with cygwin (in the C:\my_appl\tools\):
    java -jar my_program.jar -cp $CLASSPATH
    but that ended up with "NoClassDefFound"-errors about the library stuff.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: java program and libraries

    You need to change the manifest in your jar file.
    That's the only place an executable jar takes its classpath from.
    And the dependent jars should be stored relative to your jar. For example Netbeans uses the following structure:
    Java Code:
    dist
        -- your_app.jar
        -- lib
          -- all dependent jar files
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    turboscrew is offline Member
    Join Date
    May 2011
    Location
    Nokia, Finland
    Posts
    22
    Rep Power
    0

    Default Re: java program and libraries

    Oh yes, netbeans seems to copy the library files into the subdirectory "lib" in the "dist"-directory.
    Copying the "dist" directory seems to contain all needed stuff.
    Your last posting solved it!
    (Too bad I can't add to your reputation for your last posting too.)

    Thanks!

Similar Threads

  1. JAVA graphs & charts libraries
    By acornel in forum AWT / Swing
    Replies: 1
    Last Post: 10-24-2010, 07:11 PM
  2. Installing Java libraries
    By DC200 in forum New To Java
    Replies: 13
    Last Post: 03-21-2010, 05:58 AM
  3. Java Media Libraries
    By SilentCodingOne in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 05:21 AM
  4. Java 3D Scene Graph Libraries
    By sweeyt in forum AWT / Swing
    Replies: 1
    Last Post: 04-10-2009, 08:26 AM
  5. Location of java class libraries on Sun
    By phudgens in forum New To Java
    Replies: 3
    Last Post: 02-05-2009, 04:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •