Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set jar file to remove lib from classpath using NetBeans

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>
like image 317
Weasemunk Avatar asked May 02 '16 19:05

Weasemunk


1 Answers

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

like image 70
darshgohel Avatar answered Oct 22 '22 08:10

darshgohel