7

I am using NetBeans 8.1, Apache Ant 1.9.4, and Java 1.8.0_66.

In our local network deployment environment, we have an apps directory with a /lib subdirectory. We have a library (Library.jar) in /lib which is dependent on other libraries (Dep.jar) within /lib. Many applications (App.jar) are dependent on Library.jar. Many of these libraries and applications were built some time ago and use older versions than what I mentioned (Java 1.6 or earlier).

Previously, the manifest for App.jar would reference Class-Path: lib/Library.jar and Library.jar would reference Class-Path: lib/Dep.jar.

This worked until we made some fixes and updated Library.jar to the latest version of Java. Now, when we run App.jar, Dep.jar is not found, though our manifests look the same as they did before. App.jar is now looking for lib/lib/Dep.jar instead of lib/Dep.jar because Library.jar is in the /lib directory.

Our best solution so far has been to edit the Manifest.mf file in Library.jar to Class-Path: Dep.jar. This prevents App.Jar from going two libs deep to look for Dep.Jar. However, editing jar files is not something we would like to make common practice, so we would prefer a solution within the NetBeans IDE or something we can add to the build.xml that will remove lib from classpaths in the jar file and allow us to reference a jar in the same directory. I would like a solution that does not involve package-for-store, as we would like to update our dependent jars while maintaining pointers to them.

Additionally, I would like to know what caused the change in the first place, be it a version update or otherwise. Any help would be greatly appreciated.

Current build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Library" default="default" basedir=".">
    <description>Builds, tests, and runs the project Library.</description>
    <import file="nbproject/build-impl.xml"/>
</project>
Weasemunk
  • 455
  • 4
  • 16

2 Answers2

1

You can use <path> or <classpath> of Apache Ant as define below,

<path id="ant.classpath">
    <fileset dir="common-libs">
        <include name="*.jar" />
    </fileset>
</path>

in your build.xml which can point to the folder where your required ``*.jar" resides.

And then use this path at the time of building the application in target of your build command.

More reference, Path-like Structures

And, Where are classpath, path and pathelement documented in Ant version 1.8.0

Community
  • 1
  • 1
darshgohel
  • 382
  • 2
  • 13
  • Thanks, this looks promising, but I have a few issues with it. 1. We have a large lib folder, so I would like to point to individual jars instead of the whole folder. Do you know how to do this? 2. Is it possible to implicitly call a build target from the Netbeans built-in build? I would prefer a solution that can be more easily streamlined for multiple users. – Weasemunk May 17 '16 at 14:16
  • The ` ` is just an example. You can specify different options as per your requirements. Kindly go through [Maven Documentation](https://ant.apache.org/manual/using.html). – darshgohel May 18 '16 at 09:42
  • Thanks, I'll take a look. How about the second question? Could I get this to work by clicking the Netbeans "build" button, or will I need to right-click the build.xml and do "Run Target"? – Weasemunk May 18 '16 at 13:16
  • I have never used Netbeans (as I prefer other IDE like Eclipse and intellij idea), but i think you can go through [NetBeans Ant-Based Project Type Module Tutoria](https://platform.netbeans.org/tutorials/nbm-projecttypeant.html). – darshgohel May 18 '16 at 17:39
0

When using IDE (Netbeans or Eclipse), you do should not touch manifest files at any time. IDE does everything for you, based on your project setup.

So assuming you have Netbeans, please do as follows:

  1. Delete all entries from your manifest files.

  2. Go to each project in Project navigator, right click and select Properties dialog.

  3. Go through all your project and select the same Java platform for them. If project are written in older java you can upgrade them without any problems. All java code is backward compatible seamless. Nothing bad will happen if your older java projects get ported to new latest java.

  4. After this step is done, you need to set inter-project dependencies / references. You manage all references in Libraries category of Project properties dialog, tab called "Compile". If dependency is a Netbeans project as well, click button Add project. If dependency is external third party jar, select Add jar/folder.

In this way, when everything is done, Netbeans writes ant script in background and everything is taken care automatically. There is absolutely no need to touch MANIFEST.MF files.

While this setup process is in progress, you can check how things are proceeding inside your project's dist folder on the disk. (shift+F11 cleans and builds project).

Mitja Gustin
  • 1,723
  • 13
  • 17
  • Managing these dependencies is not the problem. The issue is that Netbeans adds a "lib/" to the classpath by default. An intermediate jar lies in the lib folder, but it points to a non-existent lib/lib/ since it is already in lib/ and looking for a lower lib/. Though the old and new manifests look identical, the references worked correctly in the past. Thank you for the attempt – Weasemunk May 18 '16 at 13:12