How do I deploy applets(class files) in netbeans? - java

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.

Related

ECLIPSE: How to export the smallest jar file

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.

hibernate.cfg.xml is not exported to executable jar

When I'am trying to export my project to a executable .jar-file then configuration files like hibernate.cfg.xml or log4j-properties are not exported into the jar. I have to add them manually to the archieve. The files are located in the /target/ folder in the root folder of the project.
How do I get Eclipse to export the config files too?
Just create a resources folder parallel to your source/src folder, and keep your configuration files in it.
If you use the Eclipse approach:
Project >> Export >> Java >>
Runnable JAR File >> Package required libraries into generated JAR
Only the class files get exported in the jar and - if this option is selected - the linked libraries.
You can, however create an additional source folder (name it resources or config or whatever fits your case) and copy your files into this one. This directory will then also be part of your generated jar file.
The problem of non-class files not showing up in the exported jar file may be due to Eclipse hiding the output folders. That is what happened to me. The problem was that the bin folder for a project my project depended on was hidden by Eclipse. Fixed that by using the Project Explorer to get Eclipse to make the output folder visible.
See what can I do to make display the bin folder on eclipse?
Using Eclipse Oxygen, fixed it by:
-- Selected the project with the hidden output folder in the Project Explorer
-- Clicked on the triangle in the Project Explorer
-- Clicked on Filters and Customization
-- Make sure the Filters Tab is selected.
-- Uncheck Java Output Folders

Placing application files in bin folder

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.

How to export a a jar file correctly?

I mean I tried to export my java game like this : EXPORT>Jar File but if I do this it doesn't start.
And if I export to executable jar file it doesn't export my resources into the jar file.
I mean if I play the game in eclipse the sound works. But if I export to executable jar file it doesn't work. I guess it is not exporting the sound too.
This is the code I tried to use to launch the jar file :
java jar -cvfe ProjectZero.jar Main.Launcher Main.Launcher.class
Here are two solutions for solving this problem, hope this is clear enough:
Solution #1 - You want your resources outside of the JAR file
Just copy/paste the folder containing your resources in the same folder containing the JAR file. (Make sure the directory matches pathes mentioned in the application.)
Solution #2 - You want your resources inside the JAR file
If you want the resources to be directly included in the JAR file, you could use the function getResource() to get the images/sounds. Then make sure that resources are visible in both: "/src" and "/bin" folders.
For example, if you have the following application code:
ImageIcon myIcon = new ImageIcon(this.getClass().getResource("/resources/icon.gif"));
your file should be visible in:
/myApp/src/resources/icon.gif
/myApp/bin/resources/icon.gif
Then you can export your application as a JAR file, it will contain the resources.

Add resources into a jar upon building

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)

Categories

Resources