Reputation: 455
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>
Upvotes: 7
Views: 2766
Reputation: 1781
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:
Delete all entries from your manifest files.
Go to each project in Project navigator, right click and select Properties dialog.
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.
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).
Upvotes: 0
Reputation: 382
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
Upvotes: 1