• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mixing .class files and .jar files  RSS feed

 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my situation:

  • I use NetBeans IDE for development
  • I have my own class libraires packaged as jar file
  • I have 3rd party class libraries such as Apache commons-cli packaged as jars
  • I have a class library, developed using SWIG, that wraps a proprietary network protocol distributed as a directory of .class files and a JNI dynamic library


  • I cannot figure out how to package my application for multi platform distribution.

    If I specify a class path in NetBeans the program runs inside the IDE (big deal).

    If I package the .class files into a .jar I can get the program to run from a command line but the problems are a) the jar is system dependent because of the dynamic library/shared object and b) updates for it should be independent of my program.

    Is there a way to specify a class path when you're using .jar files or do I need to write my own class loader?

    Joe
     
    Paul Clapham
    Sheriff
    Posts: 22835
    43
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Joe Areeda wrote:Is there a way to specify a class path when you're using .jar files or do I need to write my own class loader?


    Of course. That's what the "Class-Path" entry in the JAR's manifest is for. Have a look at Oracle's JAR tutorial, especially the part about manifests.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7992
    143
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why not distribute it as an archive with a structure like this:

    - My Application
    | - lib
    | | - commons-cli-1.2.jar
    | | - myclasses.jar
    | | - network-windows.jar
    |
    | - MyApplication.lnk


    Make a jar out of the network library for every os, and distribute it with your archive. In the application shortcut, you can just run the application like this: "java -cp lib/* com.example.MyMainClass"

    If you don't want to use a shortcut because you don't have java.exe on your PATH, you can add lib/* to your executable jar's manifest file's classpath, and run your jar directly.
     
    Joe Areeda
    Ranch Hand
    Posts: 334
    2
    Java Netbeans IDE Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephan van Hulst wrote:Why not distribute it as an archive with a structure like this:

    Make a jar out of the network library for every os, and distribute it with your archive. In the application shortcut, you can just run the application like this: "java -cp lib/* com.example.MyMainClass"

    If you don't want to use a shortcut because you don't have java.exe on your PATH, you can add lib/* to your executable jar's manifest file's classpath, and run your jar directly.


    Thanks Stephan!

    That is what I'm doing on systems I control where I run or test this app. And it might very well be the only way to do it.

    There are 2 issues with this approach that I'm trying to avoid. that are different from every other class library that I've used.

    #1 is that as Java Guy, I have to know in advance every system the SWIG Guy is going to build the library. In advance. So if he builds an installer for Ubuntu 13.10, I have to create a new version of my app (hopefully with no changes in my stuff) to support it.

    #2 If I repackage his libraries, I sort of become responsible for the installation of his dependencies also.

    Neither of those is end of the world I'll never do that kind of problems. I'm just looking for a nicer way to do things.

    Joe
     
    Paul Clapham
    Sheriff
    Posts: 22835
    43
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think you're mixing up the problem of how to structure your applications (e.g. what Stephan described) and how to install them. I tend to be of the opinion that you should use Java Web Start to install your applications, and when you do that, the question of how to organize the jar files kind of goes away.
     
    Joe Areeda
    Ranch Hand
    Posts: 334
    2
    Java Netbeans IDE Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Paul Clapham wrote:I think you're mixing up the problem of how to structure your applications (e.g. what Stephan described) and how to install them. I tend to be of the opinion that you should use Java Web Start to install your applications, and when you do that, the question of how to organize the jar files kind of goes away.


    That's an interesting distinction Paul and the fact that I have to think so hard about it does imply I'm confused.

    I think I have to go into more detail but don't want to bore you. So here's the quick intro feel free to ask for more details.

    I work in a scientific collaboration with institutions all over the world. I work on two related applications one is written Matlab and one a web service written in Java running under Tomcat/Apache. They both use this proprietary network protocol. The Website has my implementation that calls the C libraries directly and the Matlab program uses these SWIG bindings packaged separately and installed with native packages on Mac, Windows, Scientific Linux and Debian Squeeze. Matlab uses its own class loaders and reflection methods to access the library and that all works pretty well.

    Both programs access remote data stores with about 5 PB growing at about 1 PB/yr and provide general display and analysis routines.

    A new data type was introduced and I came up with a Java app that uses the SWIG bindings to display it. The main class has a static main method that decodes command line arguments and setter methods so the class can be instantiated inside a GUI like Matlab or a Web interface. My hope is that the single app will work in all 3 situations and it sort of does except for the packaging issue. Which relates in my mind to both structure and installation. One more thing, the command line version is needed to run the program in batch mode because looking at long periods of data can take hours to run. For the record run time is 90% network transfer in most cases.

    I haven't seen a way to use javaws for this. Perhaps an installer could use that paradigm.

    My conceptual problem is mostly how to fit my Java programs in with the SWIG bindings and underlying C libraries that are installed on the user's computer. I don't have control over how those libraries are packaged or installed and I worry about repackaging my own versions for fear of version clashes with 2 copies available at runtime.

    I do appreciate the discussion. The exercise of trying to explain the problem has been helpful all by itself.

    Best,
    Joe
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!