My project's jar file size is getting bigger and bigger as more stuff is added into it. I am wondering if someone has tips on how to generate a smaller jar file.
I export it as a Runnable JAR file and the library handling is Copy required libraries into a sub-folder next to the generated JAR.
In the Properties - Java Compiler - Classfile Generation, everything is unticked.
With these options, I was able to save approx 3MB of space. And I am hoping I can save more by removing the unneeded data.
My .jar file has a .java._trace files in it. How can I remove this from the jar file?
A .xtend and .class file is also there for each class. Since the .class file is just a conversion of the .xtend, I want to remove either one of these from the jar file. How can I achieve this?
I would appreciate any tips and tricks that can help me reduce the size of the jar file.
If you want to exclude the source code file from the generated JAR file of an Xtext based project (and I think any Eclipse plug-in as well), open the plug-in.xml file which is located in the projects root folder. Navigate to the tab "Build" and make sure that your source folders are not selected. Normally there are three source code folders "src", "src-gen" and "xtend-gen". Also the "doc" folder which contains generated java doc is not necessary.
Related
my project has 2 JSwing applets(no main class).
working: thing is they have to be together as they both work upon the same database. one stores, the other reads and process.
problem: in netbeans i used build and clean& build option but they seem to generate only .jar file and no .class file in "dist" folder.
situation:i want to embed these 2 applets separately on different html pages.
how do i achieve this?
Problem
In Netbeans i used build and clean& build option but they seem to
generate only .jar file and no .class file in "dist" folder.
JAR file itself is called Java Archive. It is nothing but a bundle of class files.
You can get your .class files by using any archive utility like winzip, 7zip etc...
Just right click on your .jar file > open with winzip/7zip > and drag and drop the contents inside it to your preferred directory.
I know I can use IMG tag in javadoc. But where to put image files? If I put them along with java files, they will go to JAR file or class folder during compiling, which is not required.
How to have image files which relate with javadoc only, not with code resources?
As specified in the Javadoc tool documentation, in the "Miscellaneous Unprocessed Files" section:
To include unprocessed files, put them in a directory called doc-files
which can be a subdirectory of any package directory that contains
source files. You can have one such subdirectory for each package. You
might include images, example code, source files, .class files,
applets and HTML files. For example, if you want to include the image
of a button button.gif in the java.awt.Button class documentation, you
place that file in the /home/user/src/java/awt/doc-files/ directory.
Notice the doc-files directory should not be located at
/home/user/src/java/doc-files because java is not a package -- that
is, it does not directly contain any source files.
This means that the image files have to be provided as part of the source directory structure. The implication is that your build process should be designed to avoid copying those files to the classes directory structure. The raw javac tool does not do the copy, and you would have to configure either your IDE or build script (maven, ant, gradle, etc.) to exclude these files in the compilation or jar step.
What's going on is that I have my images and .wav files in a a project folder and it's running fine in eclipse, however once I export it into a executable jar file it stops loading images. I've tried Extracting libraries into jar file and I've tried packaging them in a jar file. What do I do? I'm panicking because I need to get this ready by tomorrow! I know I have the path right, it's starts the code, but stops after a little.
I get this error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings:
AdventureQuestv4.0.2/src/adventureQuestv/AdventureQuestMain.java
Here's the code I use to load an image
URL GiantT2 = AdventureQuestBetaMain.class.getResource("GiantT.png");
giantT = ImageIO.read(GiantT2);
I know the images are in the file, it's just that they're not loading.
check out this post.May be you are also having the same issue.
How to export jar with images on Eclipse?
Use fat jar eclipse plugin. Select all resources like .wav and image files etc while exporting.
Before exporting resolve all Java compiler errors and warnings(to the maximum extent).
While exporting the jar file with images in your eclipse ,
You must check these in the Jar Export dialog box,
1.Export generated class files and resources
2.Export Java source file and resources
Options:
Compress the content of the jar file
Add directory entries
please delete the existing workspace and reimport the source code
i hope this may resolve issue
How can I place the files being used by my application, more particularly text files that contains data that my Java program uses. For the images since it is static, I just copy and paste them in the bin folder. But I have some text files that I create during runtime and I don't know where to place them. I need a place where I can save them in and edit them sometime.
By the way, I am using eclipse IDE.
And how would I code it? Like retrieving etc.
I am reading files with Scanner, creates them with Formatter
If you using Eclipse IDE you can just place the text files in the source folder and eclipse will copy them to the bin folder when building the application. When editing the files in the source folder within Eclipse it will update the copy in the bin folder. When you edited them with an external program you need too choose the “Refresh” menu item in the Eclipse IDE.
Place them relative to the .java file of the class using them so that the copy in the bin folder will be relative to the .class file as well. The you can access them via MyClass.class.getResourceAsStream("path relative to MyClass.class"); which gives you an input stream. This works even if you package your application as a JAR file.
I want to add DLL's, images, textfiles etc to my project as resources so when I export it, the jar contains the resources so they can be used. I am using eclipse.
Problem is I have no idea how to add it. I've tried adding DLLs/pics to the src folder in the project, but when I export the jar, it is not located there
I've looked at How to make a JAR file that includes DLL files? but it only explains how to extract it, not how to add it to the project and build.
EDIT: I am using an applet to open the jar by the way, sorry for missing it!
Cheers
How are you opening the file in java?
Class.getResourceAsStream(name)?
If you are packaging the code in a jar, then you need to use that command. (as opposed to new File(name), which will get the file in the same directory as your jar)
If the file is not physically in your jar, you can check by changing .jar to .zip and extracting it, then check out this doc http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
Usually in an eclipse project, the src folder is the wrong place to put non-sourcecode-content.
You should try moving to maven as your build system, as it is highly customizable and provides you with folders inside your project for exactly that purpose. (src/main/resources)