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
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.
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
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 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.
I'm new to java with a C++ background. I'm using Eclipse and have imported projects created by maven using "mvn eclipse:eclipse". In eclipse, when I highlight a class name from another class and do "Open Declaration", eclipse would normally open the corresponding .java file.
However, for one of the classes, eclipse "Open Declaration" opens up a .class file which shows all the context of the file. However, this file is not editable. Furthermore, I can't locate the actual .java file behind it. There is a package line in the beginning of the .class file and it points to a directory that doesn't seem exist. I believe there is a way to trace back to the original .java file from the .class file but I'm not sure how to do this. Please help.
The class is likely in one of your dependency jars, so you don't have the source locally in a project. Many maven published projects allow for the source to be downloaded in a jar, and eclipse can use that to display the source, but editing it would be meaningless in that instance.
If you hit ctrl+shift+T and search for the class you should be able to see the location of the class in the bottom portion of the "open type" dialog.
In the eclipse "properties" for the jar that contains the class, you should be able to set the "Java Source Attachment" to the folder on your system that contains the source (if you have it)