Jacks
Jacks

Reputation: 587

Use JARs of linked projects instead of .class

I am building a desktop application with NetBeans 8.0.2. For my application, I have to manage 3 differents projects : The main project, and two "tool" projects that are linked to the main.

When I run the main project, it will check the JARs present in his classpath in order to retrieve the Manifest files and do some work with.

In order to have my application run correctly, it has to see the two linked projects' JARs but it doesn't, because NetBeans deals with the compiled classes of the project instead of the JAR (for debugging purposes I presume).

I found nothing about it on the Oracle documentation, and the only thing looking a bit like what I search is to create a big-fat-JAR by using another component.

Is there a way to tell NetBeans to "compile the linked projects and use the JARs instead of the .class" files ? Thanks in advance

EDIT : Here is an example when I add the project with "Add Project .." option

/C:/Users/xxxxx/Documents/GuiceProjectsRD/xxxReaderRef/build/classes/

And here is an example when I add the JAR

/C:/Users/xxxxx/Documents/JavaLib/xxxReaderRef.jar

When I add the JAR, I have the ".jar" extension which helps me identify a JAR and then look into it for a Manifest. When I add the Project, there is no path to the JAR but only to the compiled classes, and I can't work with that.

Upvotes: 0

Views: 110

Answers (1)

Joost den Boer
Joost den Boer

Reputation: 5047

I would not depend on the Manifests in Jars since you then get this kind of issues.

Have a look at the Typesafe Config library. It's a small 100% pure Java library to work with Json/Hokon configuration. Instead of relying on a Manifest, create a 'reference.conf' in each tool project. In your application, create an 'application.conf' (if needed). Load the config via 'ConfigFactory.load()'. It will automatically search all available reference.conf's, and application.conf, on the classpath, whether in a jar or not, and merge those configs into a single configuration.

I use this approach in project to be able to plugin extension. Have for example in tool A a configuration like

tool.A.class = 'my-tool-A.class'

or used nested structures like

tool {
  A {
    class = 'my-tool-A.class'
  }
}

Do something similar voor tool B. Then in your application, from the Config, you can get a list of 'tool' configs and detect the available tools like that.

Upvotes: 1

Related Questions