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.
Related
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.
I want to keep my xml files ,jar files and .log files inside the java package of src folder corresponding to specific category .Is it correct way to place like that.Can any one suggest better approach .suppose,I have test cases related to order placing,order processing and order dispatching.I made three packages for these three order management tasks and putting java test case scripts(java classes) in respective package. Now I want to place xml files needed by the scripts in the order placing package in the same package.Similarly for remaining packages also.
I want to keep my xml files ,jar files and .log files inside the java package of src folder
Sure, if they are inputs. .log files sound like outputs to me. You need to understand that resources are not files, and that packages are not directories. Consider the case where the .jar or .war or .ear file is never unpacked.
I was wondering if there is a way to add .dic and .aff files to a java project jar file (using eclipse for example)?
I have in my code a dictionary:
URL dicDic = CipherTextAttack.class.getResource("en_US");
static Hunspell.Dictionary dict = Hunspell.getInstance().getDictionary(dicDic.toString());
I need the jar file to run everywhere without needing the en_US dictionary file..
Is that possible?
Yes, a jar file is basically a zip file with a .jar extension, so you can put any file in the archive. You can then access that file from your code as long as it is in the classpath. One easy way to do it (but not so clean for big codebases) is to put the file in the same directory structure as your class files.
To access the file, you can use Class.getResource() as you show, giving a path relative to the class used, and it will be searched using the class loader of the class used.
So in your use case, the easiest is probably to put the file in the same directory as the class using the dictionary. For example, in your code is in MyClass, you would write:
URL dicDic = MyClass.class.getResource("file.dic");
C.f. the javadoc of the method.
Then to add the files in the jar, this will depend on your workflow and how your build your project (using Eclipse, ant, maven, etc). For example, if you use ant to compile and package your project, there must be somewhere in your build file a jar task that creates the jar file. You should then modify that task to include the dic file in the jar file. In case of doubt, and if you can't find an existing answer, I'd suggest opening a separate question about your particular tool.
In any case, for the purpose of the test, you can simply open the jar file with Winzip or 7-zip or whatever zip file manager that you use, and add the dic file to the archive.
I have a newbie Java question.
I had to make suite of J/DBUnit tests for some stored procedures we use in SQL Server. These tests use some XML files in a couple of sub-directories that I originally had placed in the same directory as my Java project.
Anyway, upon checking these tests in, our SVN manager wanted to keep the .java files in one part of the tree, and resources (like the XML files and required JARs) in another part of the tree.
So, my tests had originally referenced the XML files with a relative path which doesn't work now.
My question is:
Can I make the directories with my XML files available with the CLASSPATH (I hope so).
Assuming that works, how do I reference a file in my code that was included this way?
If I shouldn't be using the CLASSPATH for this, I'm open to other solutions.
Forget calsspath. Provide your tests with a parameter/configuration which defines the root dir for the relative paths of the XML files.
Using the classpath is no problem, the standard maven project layout looks like the following:
src
main
java
resources
test
java
resources
target
classes
test-classes
The compiler compiles src/main/java to target/classes, the resources of src/main/resources are copied to the target/classes folder, similar for the tests. If the tests have a classpath containing classes and test-classes, all works fine.
How is your project layout is, how is it build?
No, you should not use CLASSPATH in this instance since it is used by Java. However, you can use a similar approach by loading a value from an environment variable or configuration file which indicates the directory where the XML files are stored.
You can do this without making any changes to your classpath. The idea is to store the resource files in a separate directory, but have them copied to a directory in your classpath when you run your build process.
Here is an example configuration:
source Directory is ${basedir}/src/main/java
resource directory is ${basedir}/src/main/resources
In your build script, copy both the .java files and the resource files (.xml) to a directory in your classpath, say:
${basedir}/target/classes
Your test code runs against the target dir. The target directory is not checked in to SVN, keeping your SVN admin happy, and you don't have to make changes to your code.
How can I splice files (ANY files, pngs, classes you name it) and folders into a pre-existing jar file ONLY using java code. That means no jar.exe utility. I am planning to make a program that places files/folders into a specific jar file. I have looked at several tutorials on java.util.jar and other jar managing modules but none of them seem to be right for me. Do I have to do this from scratch? Here is an over view of what I am thinking:
Take the desired files and folders from within a specific folder
open the target jar and place the files and folders within, overwriting other files if need be
I'm thinking I have to decompile the jar and then repackage it (ONLY USING JAVA CODE). I don't know what to do.