How to use internal libraries / references in a JAR from Netbeans? - java

I'm in the process of creating a JAR file using Netbeans. I am coming across a problem where I can not reference images or libraries without the /lib folder present with the JAR and my images in the JAR's current working directory. I need this JAR to be self contained and so when I build it I make sure that my library file and associated images are all within the JAR file itself. However my manifest file seems to be pointing to outside of the JAR as do any references associated with my JAR file. Is there a way within Netbeans to change these options when building?

It is possible to put several files inside the Jar file, but it didn't crossed my mind to do so with the libraries.
Try to see this link: https://www.google.pt/#q=JAVA+put+libraries+inside+JAR.
As far I can see in a small rechearch, is possible using external tools, or simply using ant.
Check this link as well (as shown in the previous link I gave you): Put external library to the JAR?
Google is a powerfull tool, use it more often.
I hope I could help.

Related

How to package java libraries that will automatically work when jar file is distributed to another computer?

I've created an application which has a few external libraries, i am trying to distribute to another machine. I want the application to work from just the .jar file.
I know its something to do with the 'Resolve Project Problems', is there a way to prevent this when distributing to another machine
I have already tried adding a library to the distribution folder, it carries over but doesn't do anything with it
Run the application on a new machine without having to 'Resolve project problems' through net beans
You will need to Create a FAT jar
Two Useful links which helped me where
How to include jars in lib into project jar file in Netbeans?
https://dzone.com/articles/java-chronicle-bytes-kicking-the-tires
This didn't entirely fix the issue, i was using a dynamic file string with in my program
I copied the data folder from my application and pasted it in the store folder and rebuilt and also repackaged the fat jar. This made it work

How to create Jar file with external folders and Jars

I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html

Can I refer to a Java source path using a variable in Eclipse

Background
I'm using an Eclipse 4.2 (Juno) release to build a plugin for a Java application. The source code and classes for my plugin all reside within the project workspace. The application jar and its source code are, for various reasons maintained outside of the eclipse workspace and the application jar is produced by another build mechanism.
This isn't a problem as I have referenced the application jar file in my project using drag and drop and the 'Link to files' option specifying it 'Create link locations relative to: MYDEV', where MYDEV is a Linked Resource Variable I have created for each Eclipse installation. This lets me use the same eclipse project on multiple machines where the path to the application jar varies, but is always the same relative to MYDEV.
However, I cannot find a way to associate the application source code with this jar unless I use an absolute path. I only want access to the application source for debugging purposes.
Question
In Eclipse, how do I attach java source to a referenced jar in a way that allows a project to be used on multiple installations where the referenced source code has been relocated?
If the source is outside the proyect, then there's no way to access it without an absolute path.
The best solution is using a symlink inside the eclipse project directory to the actual source folder; eclipse won't notice the source is outside the project directory and everything will work fine, without having to relocate the source.
This is the only way I was able to do what you are suggesting (do not know if there are better ways).
Package a JAR file that contains the source code of the JAR file. Place it inside your project in a folder (you do not need to add it to your class path)
In the eclipse project right click on the JAR file and go to "properties" and then to "Java Source Attachment" From there select "Workspace" button and pick the jar file with the source code we added from the above step.
So the source attachment path will always be relative to the project. That way if you share the project via SVN, GIT or whatever, the source will always be available and it'll work if the user is running eclipse on Windows or Linux.
I've had a similar problem to you where absolute paths were a problem for people using different OS and not even using mapped drives via Samba helped that much.
Hope this helps.
The way I have solved this problem is to use a use defined library in eclipse. Here the steps that you can use to solver this problem.
Create a simple project in eclipse in the directory that contains the jars and the source code files.
Define a java user library add the jars to the user library and for each jar in the library specify the location of the source. If the source files are in a project that is in the workspace then the path will be relative to the workspace folder.
Export the user library as an .xml file
When another use wants to setup an eclipse workspace with the same setting as yours they will do two things.
Import the project that contains the jars and the sources into their workspace.
Import the user library into their workpsace.

How do I create a jar distributable for javadocs?

I've created an API that I release as a JAR file. It's proprietary so I had to strip the source files out of it.
I currently include a separate /doc folder which contains the output of Eclipse's export-to-javadoc wizard. Not bad, but I'd like to go one step further.
I'd like to distribute the javadocs as a jar file that can be easily dropped into a future project which includes the jar file for my API. I know I've seen it done this way several times with other distributions I've used, but I haven't had any luck searching.
End goal is to allow future developers to have easy access to hover over comments and things of that nature.
Thanks!
It seems it is enough to package the doc folder containing the eclipse generated documentation as a jar file. Then if you want to use that jar as javadocs of the actual jar containing the compiled .class files, you assign the javadoc jar with the "Javadoc in archive" in Eclipse and set the Path within archive as doc. It seems Eclipse looks for index.html and package-list entries in the doc folder.
Also using maven-javadoc-plugin may an easy way to do this. See the link below:
http://www.avajava.com/tutorials/lessons/how-do-i-generate-and-deploy-a-javadoc-jar-file-for-my-project.html
If your end goal is just for the future developers to be able to view your javadoc instructions when they are using your classes or methods, in Eclipse you can have option to export java source files when you export your jar library as shown in the image below:
This also allows developers to step in and view your codes while debugging.

Ignoring files from Android APK

Is it possible to ignore files from being packaged into the Android APK? For instance, I have my .psd files in the same folder as their .png counterparts, and all the .psd files get packaged up.
I know I can move them outside of the folder, but I like having them in all together and would prefer not to if possible
This is actually supported in the Android Asset Packaging Tool (AAPT).
I always put my psd-like files in the resource directories like this:
/res/drawable/_pre_production/ic_launcher.psd
Any _pre_production directory will not be added to the APK.
With this approach they're in a sub-directory of the actual images' directory, but I don't see the problem with that. It is still neatly organized. ;)
An Ant script will do the trick. If you are using proguard, even that script may be good enough for u.
Use the Maven Android Plugin and declare your resources with a matching pattern that excluded the relevant file types you dont want added (e.g. */.psd). Check out the documentation for the resource plugin and look at the Maven Android Plugin Samples project .. specifically the MorseFlash application I created and the resource plugin related setup.
You can try using the maven android plugin and adding some logic to the build phase.
If you are using Eclipse, right-click the file and select "Exclude from build path"

Categories