Importing code into Eclipse when it's not a project - java

I'm scratching my head here, trying to figure out how to get an already existing library into Eclipse.
With AndEngine it was easy, as i could simply import it as a project. However, with this one, I cannot do that (the importer doesn't find any projects in the source tree). How would I import code not archived as a project?
The specific import in question is: https://github.com/sm4/AndEngine/tree/GLES2-AnchorCenter
If it matters, I need to reference it from this Android project

Well, you can download their src and then drag and drop their package into your src folder... Thats one way atleast.. If you want to leave it in Jar form, you can drop the Jar into your source folder, add it to build path, and then use it in your project.

Related

Import Java Project, not found src

let me tell you that I'm new in Java and I'm having this problem with an Android App.
The app is made by two projects, the launcher activity(Project A) and another one (Project B) which has some common SRCs for multiple Android Apps (like http connection classes, etc).
I imported project B from A, and in my .java files of my project A, I could import without problem src from B (import path from B;)
But when I'm debbuging and it has to use a file from B, I get an NoClassDefFoundError with the path of some file in project B.
After that, my app fails and closes.
Sorry if my English is complicated. Hope you understand my problem and can help me.
I guess it's something about a missing step in my import.
Importing just puts these projects into your workspace. If they are 2 separate projects you should import them as separate projects. Either right click import and navigate to them on your file system or if they are already in your workspace, do create new java project and give it the same name as the directory of the project (The wizard will make it clear that it recognizes a java project exists in that folder).
Then check to make sure that the package names and imports one package to the other are correct. If they weren't you should errors marked on those lines.
Finally make sure that the project which you are actually running from has the other project on its build path. Right click on the project, configure build path, and add the packages. Alternatively you can use something like maven to automate the installation of this second package as a jar which will automatically update in project A when project B is changed)
Please make sure you include the classes/src from project B in your project A's build path , by right clicking on your project A "Build Path" -> "Configure Build Path". Eclipse automatically will add those classes to your class path too.
The NoClassDefFoundError usually occurs when the classes needed to compile the project are present during build time but missing during run time.
Hope this helps !!
To reference other projects source in current project, just import them into your current project by adding them to your workspace. This link has some neat steps to accomplish this. You can follow which one suites you.

implementing the NWalign.java alignment script for needleman wunsch algorithm

I'm trying to run the NWaling.java file found here. the code present at the link that I mentioned makes use of the jaligner library. I have downloaded this Java package from here. inside the zip folder there is a JAR file. I'm developing the code using eclipse. whenever I add this JAR file to the code there are some classes missing for example:
import jaligner.NeedlemanWunschGotoh;
&
import jaligner.matrix.MatrixGenerator;
also in the entire zipped folder there isn't any pom.xml file to allow me to import the entire folder as a maven project to eclipse. can somenone suggest me how to import this jaligner library and use it in eclipse? thanks.
You can download a community implementation of the jaligner algorithm from here.
Take a look at this project sources where you may perhaps find all the searched artifacts.
The full Eclipse project with the NWalign.java can be found here including .classpath file with all dependencies listed there.

How do I use classes from an imported library in netbeans (java)

This must be the simplest thing. I have been trying to do this for hours. I know how to import libraries into netbeans but how do I use classes in these libraries using imports? I have been trying unsuccessfully for hours to use the javacv library on 64bit linux and when I try to import the necessary files from the library netbeans tells me the package does not exist. I want to access a java file example.java inside com.googlecode.javacv.cpp.linux-x86_64 which is inside opencv-2.4.8-linux-x86_64.jar. How do I actually import this so I can do the following: example obj = new example?
Also, in almost every reference to javacv I see this import com.googlecode.javacv.CanvasFrame; but nowhere have I actually seen this in any of the files readily available by google. What's the deal?
Please give this a try, I will be as specific as possible:
Copy the library folder you want to use
Paste it in the "src" folder of your project folder
Once you completed the above two tasks, you can import different classes from the library using the following code:
import nameOfLibraryFolder.*;
The above code will import all the classes from within the library. Replace "nameOfLibraryFolder" with the name of the library folder, to be more specific, the folder that contains all the classes of the library, to be even more specific, the folder that you placed in your project's subfolder called "src".
In order to import a specific class from the library, you need to replace the * symbol with the class name.
For example:
import nameOfLibraryFolder.className;
but if the class is in a subfolder, then:
import nameOfLibraryFolder.subFolderName.className;
I hope this is specific enough, and I hope it helps.
In netbeans, it is rather easy to iomport a external jar and utilize it.
First you need to add jar file in project tab by right clicking on the library node.
Then, in this project, just import the.name in your java file.
This should work, I have used Netbeans for three years
You many need to do one of the following option.
Add an new Library to NetBeans, then add it to you project
If you Tools -> Library a popup will come up.
There you can add a new library. Click on New Library and name the new Library.
Import a library from the ClassPath tab Add Jar/Folder
If you want to can also add the javadoc from the JavaDoc tab. You would add the file from the library file you downloaded, called javadoc. This will allow for the javadocs to be seen while editing your code.
Also you can add the sources file form the Sources tab. Import the file named sources
Then click on the Libraries folder icon in your project and Add Library
Another option is just add the .jar.
Right-click on the Libraries folder icon in your project and click Add Jar
Locate the .jar file and add it.
As long as you have:
package MyProject;
At the top of your project Java wont recognize it.
* It seems to be like some sort of sandboxing affect.
* To use your classes you have to open the directory you
* Saved the project to and Copy/Paste the library to the source file.
* I also found that simply deleting the named package works as well.
* But now you're no longer linked to that package. -shrugs-

Importing source code of a library in Eclipse

I have a question about importing .java files.
I have downloaded source codes of a library that has many subfolders.
The way that I imported is to create a new folder within my project called libs and dragging dropping the entire folder, after that I right clicked into the libs folder and then clicked Build Path-> Use as Source Folder.
Now the issue is most package names are like "analysis.common.src.java.org.apache.lucene.analysis.ar" whereas within their source code their package name is referred as package org.apache.lucene.analysis.ar;
How can I fix this problem? Using CTRL + SHIFT + O does not fix it.
You can use Eclipse File System Import to import sources to a particular project. Here is a step by step explanation.
Another example. Scroll down to "Importing Files Into a Project" section

Building Android Source apps In Eclipse

I downloaded the source to spareparts here
https://android.googlesource.com/platform/development/+/gingerbread-release/apps/SpareParts
It includes Android.mk, AndroidManifest.xml, Notice, res and src folders.
My question is how can I compile this source code in Eclipse? I see there is a make file (Android.mk) which I'm guessing I need to use but I can't figure out what to do to get this thing imported into Eclipse without having 500+ errors.
This article seems to have the answer. According to it you would need to download all of the source just to build one of the apps, though.
Brute force always works :)
Create a new android project in Eclipse named SpareParts
Use the explorer to replace both the src/ and res/ folders inside workspace/SpareParts with the ones downloaded form git
Click with the right button on the SpareParts entry in the project tree in Eclipse -> Refresh
enjoy
I looked into the files and it does not seem that it uses any external library.
If you try to build it by itself, you will still have problems due to these three classes that are not in android.jar:
import android.app.ActivityManagerNative; //cannot be resolved
import android.os.ServiceManager; //cannot be resolved
import android.view.IWindowManager; //cannot be resolved
In Eclipse try File->Import... and General->Existing Projects into Workspace, add the project folder and then try to compile it. Hope it helps.

Categories

Resources