I am a beginner of Java and Eclipse. Now I have a Java plugin and its source file. I want to debug the source file in Eclipse to see how each part of the code runs. I created a new project named first trial, and the structure is like this:
src\analyser: 1.java,2.java,3.java...
GUI: 1.java,2.java,3.java,4.java,5.java...
GUIPanelWindow: 1.java...
main:1.java...
segmentation: 1.java...
tracking: 1.java
There are more than 5 classes in each package. It's based on the third party-Fiji, so at the beginning of each class it shows the syntax like this "import ij.Prefs","import ij.plugin.PlugIn" and so on.I have also added external JAR files into the library, but it also shows the error "The import ij cannot be resolved ". Thus, the result of debug shows that
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at main.LineageTracker.main(LineageTracker.java:320)
I want to know if I can debug a Java source file like this or what other steps I should do? I will appreciate your help.
Following up on PM 77-1's comment, assuming ij is in one or more JAR files, here's how to add those JAR files to your Build Path (tested on Eclipse Kepler, the most recent version):
Right-click on your project (first trial) in the Package Explorer.
Select the Build Path submenu.
Choose Add External Archives.
In the resulting JAR selection dialog, choose the JAR files for ij. You can select more than one file.
Hit OK.
The JARs you selected will appear in the Package Explorer, below src, under Referenced Libraries.
Build and hopefully it will work!
Related
I'm new at java programming so i just wanted to try something with ssh understand how it works and so i downloaded a java library which is mentioned in this Stack Overflow answer
. After a lot of failed attempts on importing this library into netbeans. I decided to simply put the files into my src folder. But Netbeans ide duplicating packages in the jar file with their 'name equivalent' empty packages and this prevents me to reach the classes in the packages because the IDE and the Code completion automatically sees the empty packs.I've search the network couldn't find anything about this problem.I 'm ready to share any log files if there are any of them .Here is my screenshot about this situation.
Screenshot Attachment
OS : Linux Mint Rosa
IDE : Netbeans 8.1 Linux version
Edit : I Already looked these topics
How to use .jar files in NetBeans? : At first i've tried this and in this solution netbeans not duplicating any empty packs but when i start to type somethin' like that import sshj.foo.*; Auto Complete can't find anything and also if i try to write the whole path to a specific class which is in an specific pack IDE gave me an error the pack that you're looking for is not exist.Secondly I've tried this
and got the same issue at first try.I can see the packs,classes and other stuff but still can't reach them in a random class which is imported project.
How can I include external jar on my Netbeans project : I've tried this and also this ran perfectly without errors as they said but when i try to reach classes still got the same problem so nothing changed.
How to add a JAR in NetBeans :
In this topic all of the replies explained types of libraries.That's not even related to my problem
How to use classes from .jar files? : I've tried to do explained in this reply also and I've transfered my jar file into a compiled .class extension file and this didn't solve my issue too.
I've just solved that problem with downloading part of the libraries from here.
All libraries need to contain three kind of jars ;
1 . Compiled files containing jar (with extension .class)
2 . Source files containing jar (with extension .java)
3 . Javadoc files containing jar (optional)
Open a project find libraries folder on ide right click and choose Add JAR/Folder specify the directory that contains the compiled files.After importing library hit right click over it and choose edit then specify the source files and javadoc files directories you are ready to roll.
I decompiled a jar, imported the files into eclipse, and edited a few key java files. Whenever i try to export however, it gives me a
"JAR creation failed. See details for additional information. UHC-2.4.1/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF and is no longer in the JAR. uk/co/eluinhost/UltraHardcore/features/core [in UHC-2.4.1] is not on its project's build path Unable to get package fragment root: UHC-2.4.1/uk/co/eluinhost/UltraHardcore/features/core/GoldenHeads.java uk/co/eluinhost/UltraHardcore/features/core [in UHC-2.4.1] is not on its project's build path" error.
I have searched far and wide for a solution, but have nor found one. I have tried refreshing the project etc, and all the necessary libraries are specified. Please help? Additional information: If I edit any other class (just add a space then delete it and then save) that class gets added to the error message as well.
I had the same issue. I noticed that all of the files that were listed as "not on the project's build path" were open for editing in Eclipse. Once I closed all of the open files, I was able to export the jar.
I assume they are locked for editing and so not exportable.
There are two issues:
It looks like you have the MANIFEST.MF file (UHC-2.4.1/META-INF/MANIFEST.MF ) so just
when you are exporting the jar file select the option for existing manifest file and point it to UHC-2.4.1/META-INF/MANIFEST.MF .
You are missing a jar file (download the UHC-2.4.1.jar from here and and add it to class path.
I know you wrote that you have all the "necessary libraries" but make sure you have added them to your class path.
Import the project from the parent folder, that's what fixed it for me.
In case you haven't noticed, they are not packages in your eclipse picture, that's one reason
I have a Java JAR file that was developed to run in the browser. It works fine. There doesn't appear to be any sort of build file associated with the source code I've been given and I'm attempting to create a project and/or build script.
The source code references some third party code. What I've done is unzipped the JAR file into a folder that has this structure:
\App\src\com
\App\src\META-INF
\App\src\applet
The "com" folder contains subfolders which contain the .CLASS files for the third party libraries. "applet" contains the .JAVA source code files (one folder, maybe 15 files).
The code appears to be written in 1.4 syntax (I manually attempted to compile some of the .JAVA files and it complained that some things were deprecated and/or required the older version).
I created a Java Project in Eclipse and pointed it to the \App folder. Then I went into the Properties for the project and went to Libraries and and clicked on "Add Class Folder" and added the \App\src\com folder. Then I went to "Order and Export" and moved this to the top. I also set the Java Compiler version to 1.4.
I am getting a large number of compiler errors, all of which seem to stem from the fact that it says it can't resolve an import. This import is the set of .CLASS files contained in the "com" subfolders. The namespace matches the directory structure.
This seems like it should be really straightforward, but I've tried various things and don't seem to be making any progress. Based on what I've read I'm sure it has something to do with the pathing but I'm at a loss at this point on how to fix it.
(I'm sure it goes without saying that I'm not a Java dev.)
Any thoughts or ideas as to where I'm going wrong?
Can you please try to right click on Eclipse's Navigator. Select Import>General>archive file> (Jar file that you want to import).
You should be getting the jar file correctly imported at this point. Do tell me if you face any problems.
This question already has answers here:
Error: Selection does not contain a main type
(24 answers)
Closed 8 years ago.
I am receiving the errors: Editor does not contain main type, or, Selection does not contain main type when I import an archived Java project into Eclipse and try to run it. I have gotten this error on several different operating systems.
Archive Protocol
Export project
General->Archive File
All are selected: project folder, .classpath and .project
[x] save in zip format
[x] create directory structure for files
[x] compress contents of file
A Work Around That May Explain It... but how?!
I notice that when I import an archived project into an existing project (a blank Java project), The folder hierarchy is something like:
Project
src
bin
imported_project
bin
src
actual_code.java
Now, when I try to run actual_code.java, I get the above error. I discovered the following work around: if I drag actual_code.java and drop it into Project->src and then run it, it works.
This is a nice work around. However, I would prefer to be able to run the imported project without moving things around. Any suggestions on how to do this? It seems like it should be a trivial fix--it simply seems like the project isn't importing to where it ought to.
And yes...
I have tried every method I have come across to remedy this. That includes quite a few from this site and others: syntax, libraries, source path, restart eclipse, rearchive, different operating systems, different machines... etc.
The .java files are in the src folder before I archive them, and my build path seems correct.
You could import the archive as a Project instead of as files into a newly created blank project. Use Import > Existing Projects into Workspace. Then, use Select archive file.
You might want to put the src folder of your imported_project in classpath.
Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder
I also faced the same error ajnd after reading above article i just drag/drop my class-file to src and new class-file generated in src is working fine .
I had the same problem after I New/Java Project then pulling src, docs, lib, examples, ... folders. I could not import it as an Eclipse project since the code is not an Eclipse project. The main is right there in the example code, but the IDE would find it.
The solution for me is deleting the project from the IDE, then recreating it with the Eclipse IDE. When recreating, the IDE cached all the sub-folders for me. Also, make sure you add the code onto the Java Build Path as Source using the 'Configure Build Path...' of the project.
Restarting IDE, closing then reopening the file didn't help me.
I have a simple Java project in NetBeans7.2, and when I try to Clean/Build it fails:
Building jar: D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar
To run this application from the command line without Ant, try:
java -jar "D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar"
Realizando o ofuscamento do código
Obfuscating dist/Mina.jar...
Created dir: D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\build\obfuscated
ProGuard, version 4.8
Reading program jar [D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar]
Reading library jar [C:\Program Files\Java\jdk1.7.0\jre\lib\ext\jna.jar]
Reading library jar [C:\Program Files\Java\jdk1.7.0\jre\lib\ext\mysql-connector-java-5.1.21-bin.jar]
Reading library jar [C:\Program Files\Java\jre7\lib\rt.jar]
Reading library jar [C:\Library\Java\Home\lib\rt.jar]
D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\build.xml:28: Can't read [C:\Library\Java\Home\lib\rt.jar] (No such file or directory)
BUILD FAILED (total time: 5 seconds)
It's odd because I don't have that [C:\Library\Java\Home\lib\rt.jar] called in my project's library (there is no "C:\Library" in my computer at all)!
Also, why "rt.jar" is called again, if it's already called from "C:\Program Files\Java\jre7\lib\rt.jar"?
I have absolutely no idea where this came from, nor where I can change it (because it is not in my project's library list).
Thanks in advance! Forgive my bad english...
EDITED:
I just figured out that this issue doesn't happen when the application is compiled (build), but when NetBeans' ProGuard4.8 plugin try to Obfuscate!
I suppose that by "simple Java project" you mean the "Java application" project from "Java" category in NetBeans "New Project..." action from "File" menu.
Netbeans default build system is Ant. Ant is the program that compiles, packs and runs the source code from your project.
If you can't find the string "C:\Library\Java\Home\lib\rt.jar" anywhere in the project Properties window, the next place to look for are the properties files inside the nb-folder in project root (change from "Projects" to "Files" view) or the build{-impl}.xml files.
When you click on the "Clean and Build" action from the right click on the project icon in the "Projects" view ant reads the build.xml file (which imports the build-impl.xml file), finds the clean and jar targets, calculates all the dependent targets and properties needed to successfully run the aforementioned targets and finnally runs the calculated sequence of targets.
But, if it is a project made through the NetBeans "New project" action, the build.xml and nb-project are automatically generated, and changing the project properties from GUI effectivley changes the parts of build-impl.xml and some other files. In case you hadn't edited the automatically generated files, that is not the place to look for.
The next thing is to consider if it is Netbeans cache issue, see here for it's location, enter that directory and delete its contents (I can't guarantee it will help though).
Interesting thing is that rt.jar is usually in JRE_HOME/lib directory where JRE_HOME is full path to some JRE installation, so that might lead to conslusion that you have an JRE_HOME environment variable set to this (nonexistent) location.
It's all just guesses but something of this should help you. Please feedback.