How do I share classes between two Android projects in Eclipse? - java

I have 2 Android projects in Eclipse. Now the both need to share one class. As soon as I add a Project to the buildpath of the other, the folder is added but always marked with a red cross. How can I resolve this? Thanks for any help.

You can use the feature of isLibrary project.
1)Create a new Android project.
2)Add all the classes that you want to share them between multiple projects.
3)Right click on this project and select properties.
4)From Android section in left menu mark the project as isLibrary project checkbox.
5)Right click on all the project you want to share the class with them and select properties.
6)From Android section in left menu click on the button Add and select the library project.
7)Use the class normally as if it is in your project and add its imports.
I hope it helps.
Note: The previous steps is for Eclipse

Mark project(that contains the class to be use in another) as library by right clicking the project and then properties.

You don't have to do it by means of a library project, you could use a common source folder.
If you are developing in Eclipse then the trick is to have a common source folder (common to both projects) Make this folder outside of both projects and in the build properties/source, click 'link source' and browse to the location of the common source. (You can call it any name you want) Do this in both projects and it will appear in both projects' Package Explorer and when you change it in one project, the other will get updated too.
It will have to have the same package name in both projects.

Related

Add project library error when close project properties?

I work with eclipse and I would like to use from external project library some class. Every time I open project properties add this external project I get following problem. There is no problems with another project libraries. This additional project has ticked "Is Library".
I think the best way to import an Android library is :
import your library projects to your workspace
right click your main project and properties
close to the top, choose Android
Then click add from the library section at the bottom

organize maven multi-module project in eclipse

I have a huge Maven multi-module project. With similar structure
parentA
- subA1
- subA3
- subA3
- subA2
parentB
- subB1
- subB2
etc
The problem is, that parentA and subA1 does not contains any code inside it, but I can still see them in project explorer. But I would like to hide them or organize in tree hierarchy like in an explorer. Right now there are over 30 projects and just 20 of them contains Java code. Others simply contains others modules references. I see all 30 projects in plain form in project explorer.
The first idea - was using working set, but I can't include working set in another working set. What is the common practice to handle this issue for eclipse users
go:
Windows -> Preferences -> Maven -> Hide folders of physically nested modules
and re-import your project.
We can also use working sets.
Choose Top level Elements as 'Working Sets' from Package Explorer / Project Explorer view.
Configure "Working Sets" to manage your projects. Move the Parent project to a different working set and child project in different working sets.
In Project Explorer, there's a down arrow, if you hover over it, it shows "View Menu".
Click on it, Project Presentation -> Hierarchical
Try using Projects View. It does it for me in these kind of situations.
Also, you can put filters to exclude certain projects in Package Explorer or other views that you prefer like this: go to PackageExplorer, select View Menu - Filters, check Name filter Patterns and enter the names of the projects you want to hide, separated by commas.
In other views, instead of View Menu - Filters is View Menu - Customize View.
You can find a tutorial here but instead selecting Closed Projects enter the name of the projects as I mentioned above.
As for the tree view I don't think you achieve that because in Eclipse there is no notion of sub-project. Have a look here.
From the Package Explorer view select filter from 'view menu'. Then select filters, and exclude Non-java projects.
On the package explorer window:
-> Select the three dots menu -> Then Package Presentation -> And then change from Flat to "Hierarchical"
And you are done :D
Change project view image

Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? The Java project doesn't use stuff that is incompatible with Android. I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. Is it possible? Thanks
This is somewhat of a hack, but worked for my project:
Add both Android project and plain Java project to workspace
Go to properties for Android project -> Java Build Path -> Source
Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree
Use a descriptive name for "Linked folder location", like "java_project_src".
Press Finish and compile
This setup will compile the plain-java code as Dalvik bytecode. In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project.
I think you are talking about referencing other projects into the current project, if this is the case then you can do this by Right click on project, properties->Project Reference.
You can link another projects to your current project. Right click on your main project, choose Build Path -> Configure Build Path... In the dialog choose the Projects tab, then click Add.. button. Now choose the project you want to link and click OK. You'll now be able to use this project's sources inside your main project. Hope this helps.

Problem in compiling java project in Netbeans

I have a problem now :
When I want to compile my project in Netbeans IDE I had this message error :
Problem: The project uses a class library called "toplink", but this class library was not found.
Solution: Click Resolve to open the Library Manager and create a new class library called "toplink".
In fact I didn't change anything and it works fine before?
What's the problem?
It seems that you have to import the library itself.
On the left pane in your Netbeans editor, you should have a series of panes. One of these is called the Projects pane. If you click on it, you should be able to see the files and packages which make up the project you are editing as nodes. One of these nodes, at the very end is called "Libraries". Right click on this node and select "Add Library". From there, you should be able to browse and locate the library.
I believe libraries are defined for the NetBeans installation rather than for the project. You can import a library into a project which would make it available on other NetBeans installations. Perhaps you are on a different computer or a new installation of NetBeans?

How can i make projects bound to eachother in eclipse?

I have 3 projects in Eclipse that are bound to eachother. With bound i mean this:
Everytime i add a class in one of the projects, the other projects also updates themselves and add the class
Now i want to add another project to these, but i don't know how to bind it together with the other projects.
Any suggestions?
Edit:
alt text http://img218.imageshack.us/img218/8441/eclipsesymbol2.png
This is how the projects are listed in eclipse.
Any explanation about the [smax3]?
Any explanation about the ">"?
Thanks
Thanks in advance!
(See Java Build Path Eclipse Help page)
In the build path of a project, you can declare a project in the dependency list of another.
In the tab "Projects", add the project "P" you depend on.
Each time that project "P" is changed, your project will take the modifications into account.
See that old but still accurate article Configuring an Eclipse Java Project
This illustrates two project under version control (CVS or more probably SVN with Subversive or SubClipse).
See the label decoration help page.
Here: "[smax3]" is the name of name of the SVN repo, with an "Outgoing flag" (the '>'), meaning some resources within the project need to be committed and published to the SVN repo.

Categories

Resources