(item) is not on the projects build path - java

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

Related

Netbeans automatically cloning my jar based packages with their empty 'name equivalents'

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.

How to run Java source file with multiple packages using Eclipse

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!

Having trouble compiling and recreating a JAR file using Eclipse

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.

How to use a class from JAR in eclipse

I have two jar files - jar1 and jar2. Both of them are located in C:\Eclipse projects\ and I have added the paths to both of them to the Environment Variable CLASSPATH as follows
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Eclipse projects\stdlib.jar;C:\Eclipse projects\algs4.jar
the ".;" at the beginning were there so I left them. Then I added the jars to the project from their location C:\Eclipse projects\ and they showed up as Referenced Libraries. However, when I try to instantiate a class from the jars it does not recognize it. I am also not able to import the jar (import jar1).
After I tried adding a lib folder in the project and I added the jars there. After, I added them as references once again (so not they appear twice in the Referenced Libraries), however, I am still not able to use the inner classes. Any help will be much appreciated.
UPDATE:
Something must be wrong on my end. None of the suggestions worked for me. Here is a video with all the steps: screencast.com/t/gC81YzCsLY0e
RESOLUTION In my project I had a package called TestProject and it seems that those jars needed a default package. After deleting the TestProject package and using a defaultPackage everything worked correctly after adding external JARs as explained below.
I've got the same problem as you today, And no answer from the web can solve it. However, I fixed it at last.
In fact, there is nothing wrong with the setup, it is right to import those jars through "Add External JARs". The real problem is the location/package of you java code. I found that you have to put your .java file in the default package. For example, you will get errors if you put your java code in a package like com.xxx.yyy.ccc, below is an image which shows the right location/package you should use(see WTF.java). After doing that, you program will be able to run.
However, that is how i fixed my problem, i'm not sure that could work for everyone..
In eclipse, right click on a project->Propeties->Java Build Path->Add External JARs (Add JARs if the jar is inside the project's folder) and then choose your jar file.
From now you can use the inner classes of the jars you added. Eclipse will import them when you'll start using them.
Why don't you use these two JARs—— stdlib-package.jar and algs4-package.jar.
And below the code page(http://algs4.cs.princeton.edu/code/)
Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar or algs4.jar. Why not?
A. The libraries in stdlib.jar and algs4.jar are in the "default" package. In Java, you can't access classes in the default package from a named package. If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.
Warning: if you are taking Princeton COS 226 or Coursera, Algorithms, Part I or II, you must use the default package verison of our libraries to facilitate grading.
Showing my test success:
If you have a folder with your JAR files into the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add JARs, search and select the JARs files you want to use.
If you have yours JAR files any other place outside the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add External JARs, search and select the JARs files you want to use.

jars added to WEB-INF/lib doesn't get recognized when I try to import them : says the package doesn't exist

I have added org.apache.commons.fileupload and org.apache.commons.io package into the WEB-INF/lib directory of my project based on google appengine. But when I try importing in the servlet files the compiler/IDE gives an error that this package doesn't exist. Why is that ?
The jar files added :
What can be the reason I am getting this error ? What should I do to solve this problem ?
You might also have to add them to your project's classpath.
for eclipse:
Right click the jar, select build path and add it to the build path, then try again.
for netbeans:
in the project properties window click libraries in the left panel. In the right panel add it to the compile classpath
General solution , whenever you get package does not exist then there are 2 things, 1- Its not at all present 2) its present but still the error is thrown.
The solution to this is to just add the jar to the classpath [so that your app finds it during compilation,execution)
I would suggest you to try Maven . Maven is a nice way by which you can organize this in a systematic way.
If the IDE gives the problem then update the jars in IDE project class path :)

Categories