hibernate.cfg.xml is not exported to executable jar - java

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

Related

How to import OEM Java lib and source into Netbeans?

I have done a reasonable amount of programming in various languages but I am a Java / Netbeans newbie. I have successfully created and run "Hello World" so my Netbeans installation is OK.
I want to write code to control an LED display controller card. I have sample demo code zipped up by the OEM. I am trying to import, run and edit that code. If I can get this running, this will be the starting point of my own code.
The zip files only include library and source files in a directory structure that does not match Netbeans. All of my attempts to import the source and lib files have given fatal errors in Netbeans.
The directory tree has a lib and src branch at the root. The src branch cascades 4 levels to get to the source files.
I figure if I use a different tree structure, I will need to change the import statements in the source file. I'd rather not touch the code until I have it running. I have tried to unzip the project tree directly into the Netbeans directory but that didn't work.
How to import a JAR (Java Archive, the "library" in your case) in Netbeans:
Right click on your project name, in the 'Projects' pane usually located on the left
Click the 'Properties' link from the pop-up menu
Click the 'Libraries' link in the Categories list
Choose 'Add JAR/Folder', browse to your JAR and click OK
If you want Netbeans to create the JAR for the sources you have, do like Stefano says.
You should package the src folder as src.zip with a zip utility and the structure under lib with the java archiver as a jar file.
Now you can define a library in NetBeans and add these files to it (Tools => Libraries => New Library).
For Netbeans to be able to open a project, the folder has to contain some files that Netbeans itself generates when a project is created.
Since you only have src and lib folders available, I think the easiest solution would be to create a new project from Netbeans, so that the creation of those files is automatically managed, and then copying the content of the folders you have in the folders Netbeans will create.
You will also have to tell Netbeans to use those library, and you can do that from you new project's preferences.
Edit
A few more things you can try:
in NB, right click the folder containing the JARs you imported and select "remove", then import them back but selecting the jar files instead of the whole folder;
if you're not already doing so, use the "Clean and build project" button instead of "Build project";
If none of the above solve the issue, try starting from scratch again following these steps:
unzip your OEM files somewhere in your disk;
create a new empty project in NB
copy the files from the src OEM subfolder to src NB project subfolder
in NB, right click Libraries, then add JAR/Folder and select the jar files from the lib OEM subfolder
If this doesn't work either, tell me where I can find the OEM stuff and I'll try it myself :)

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

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.

Exporting resource folder with jar

I have a folder called "resources" in my Eclipse project. It's used as source folder. Everything works well compiled from Eclipse. I wanted to try it on Ubuntu so I exported it to runnable jar and tried to run but it gave me FileNotFound Exception. I checked the file structure inside the JAR and there's no "resources" folder, only files that should be inside. I'm accessing files with
File file = new File("resources/hotkeys.ini");
I also tried
InputStream in = getClass().getClassLoader().getResourceAsStream("/resources/hotkeys.ini");
but it gave me null.
How to force Eclipse to export the folder along with jar?
When you use "Export" functionality, you need to select all resources that need to be exported (it is visible at the top of the Eclipse export wizard window).
You can find the answer here as well: Java: export to an .jar file in eclipse
You can open the jar with 7zip or Winzip, and check the path.
Try
getClass().getResourceAsStream("/resources/hotkeys.ini");
(Or try removing the first / when with getClassLoader().)
Especially check the case-sensitivity of the paths. As opposed to Windows, inside a Jar it is case-sensitive.

Build java library with resources

I am trying to make android java library, but when I build my project in output jar library placed only java compiled classes, but no resources and assets.
Also my project contains native libraries, I need to include it in jar too.
PS: I have connect my library project to another project.
PS2: I have find out that resources from library project (res, libs) compiles into apk file, but assets not. How to make assets compile too?
To export jar with resource file please follow the below steps.
1) Right Click on Project Folder
2) Then Click on Export
3) Click on Java -> Jar file.
4) It opens a Jar Export Dialog . Please ensure that Exported generated class file and
resource check-box is checked.
5) Then provide the export destination .
6) Finally click on finish button.
In export menu for eclipse, you have a check box asking you for the inclusion of source files

Cannot assign source to jar in eclipse

I'm using a java jar file in my eclipse project. Beside this, I have a "normal" folder including the sources of this jar. Now I created a folder "lib" in my eclipse project, added the folder with the source files into it and attached this folder to the jar file. But everytime I want to open the code definition by clicking on a class (ctrl + click) I get the message "assign source code"... What is the mistake?
Does you JAR file only have .class files in it? If so you will need to Attach the Source i.e. .java files. I don't know if you have the .java source files in your possession.
If you do have the .java files (or they're in the JAR and aren't being picked up) you can use the "assign source.." dialog to point Eclipse to the location of the source files. If you don't have the source files, but want to see it then consider installing an Eclipse decompiler plugin e.g. JD-Eclipse

Categories

Resources