Can't call a class from another git project in Eclipse - java

I imported a project from github into Eclipse (project A), using these steps: Importing a GitHub project into Eclipse
I have another app engine project I am building in Eclipse (project B). I would like to import a class from the project A to project B. I was trying to follow these steps: How can I refer to a class from another project in the same Workspace in Eclipse/Java
But when I go to project B's Java build path --> Projects --> Add, the select project window does not show the imported github project.
If I create another local Java project (project C), I can see project C as an option to add to project B's build path.

Make sure you are copied project A into your workspace while import into eclipse.
There is a check box option for copy project into workspace in eclipse import project.

First, You will have to fix the project A at eclipse before importing into the project B... By fixing, I mean setup the source paths of the project A (example, the folder src/com/google, should be a source folder at the project A configuration)... The Project A must compile (if the project A cannot be compiled by eclipse, I doubt that you will have success at importing it into project B)
Another strategy would be use the ant script of the project A and import, as java library, the artecfacts generated by those ANT files into the project B.

Related

How to identify project type from project folder

Recently i have received a project as a zip. I have unzipped and now i want to import the same in eclipse. But am unable to identify what type of project(maven, java, gradle, etc) it is. I have tried importing as existing project into work-space. But its not identifying as a project when searching in eclipse.
For maven projects, it will have a pom.xml, this one don't have one.
Similarly is there any other ways to identify what type of project it is from the project folder?
Thanks in advance!
I have received partial answer from the commends of #Sangeeta and #carchingUp. I want to add all details to a single answer so that it will be helpful to others.
Inputs from Sangeeta: if pom.xml is present you can infer its a maven project. If build.sbt, then its an sbt project. If build.gradle, You can know its a gradle project and build.xml for ant projects
In my case i was having build.xml from which we can identify as ant project.
When you import the project as ant project to eclipse and if you have the below scenario,
"package name is com.abc.xyz, present in src/main/java and when importing as ant project, main.java.com.abc.xyz becomes the project and am getting error for all the java files for package name mismatch", follow the below steps.
right click the src folder >build path >remove from build path
right click the java folder > build path > use as source folder.

Eclipse I can't link project B to project A

I work with Eclipse. I have two projects in the workspace. This is my Eclipse navigator.
I want to add AR04.CME to cmeWeb.
Folder cmeShare has some jar which I need in cmeWeb.
I click in cmeWeb properties ->Java Build Path -> Projects
This is the screen
AR04.CME doesn't appear as project.
How can I add this project?
Linking Project A to another Project B is useful when you have source code in A that you want to share to B. That's not your case. You don't seem to share source code, but a compiled library instead.
Your best option is to edit cmeWeb's Build Classpath > libraries > add jar > select your Jar library.

Maven package structure changed after build Eclipse

I created a Maven project in Eclipse. Initially my package structure was like
-src/main/java
---com.package1
---com.package2
-src/main/resources
When I build the project successfully and got war deployed in tomcat, My project structure changed to
-src.main.java.com.package1
-src.main.java.com.package2
-src.main.resources
This is generating errors in Java class files in packages import declarations.
I want to restore my original project structure. I have m2eclipse plugin installed in Eclipse.
I also tried Maven>Update Project.. (I read somewhere on Stack Overflow that it will restore the original structure) but it is generating the following error
Failed while installing JAX-RS (REST Web Services) 1.1.
org.osgi.service.prefs.BackingStoreException: Resource /Workspace/ProjectName/.settings' does not exist.
Please help how I can restore my project structure back.
The following helped in my context:
Eclipse Luna (4.4.2) with Maven embedded
Multi module project where folder structure is
parent P
module A
module B
P is a normal Eclipse project while A and B are Maven projects
P is a closed, A and B are opened
the error happened in B with message Resource /P/B/.settings not available
After opening P again the error disappears and Project>Maven>Update Project... works fine.
It seems you have created the src/main/java and src/main/resources as normal folder. Just change them to source folder. It will work.
Steps
1.Go to src folder & Right Click
2.New->Others->Source Fokder
3.Then make the folder structure as /main/java & /main/resources
4.Then add the packages.

Eclipse: reference sources from other project

I've got two projects in Eclipse. Both have some source files, and I want to reference sources from one project in another one. The only thing that works is
Project Properties -> Java build path -> Projects
Where I add the required project.
The problem is that when I'm trying to launch the project1 activity it starts and then launches project2 default activity.
How could I add sources from another project?
If you want to use another project as an library in your Android project add the project via Project Properties --> Android --> Library. The referenced project should be marked 'Is Library' on their own properties page.

add other projects as library in netbeans

I have a project A (for example an Ant based Java Application project) and a second project B (a Java Class Library project or another Java Application project, both Ant build based.)
Project B has some additional Java library dependencies (.jar files in the Libraries folder).
A depends on B. A can use classes which are written by myself in B but it can not see classes in the additional libraries of B unless I add those libraries/jar files to A.
Is there a way to get NetBeans to automatically manage the library dependencies in A by including the dependencies of B in addition to B's own jar file? In eclipse when you add .jar files to project B, it is not necessary to add them to A again.
Thanks.
In your project folder you should see a folder called Dependencies, right click on that folder and choose Add Dependency.... Open the Open Projects tab; from there you can select your project from the list. Click Add.
This works for NetBeans IDE 7.2.1.
The simpler NetBeans Ant project Libraries folder is used for compile time and run time dependencies of each individual project. If your "Java Class Library" type Ant based project B has additional library dependencies, they are not automatically forwarded or updated in Project A when you include B as a library of A.
When project A is built, it's .jar file will only contain Project A code and the lib/ folder will only include .jar files from it's Libraries folder. This can cause confusion when you upgrade the dependent library versions and possibly forget to upgrade them everywhere you depend on project B.
You will need to manually manage the dependencies unless you switch to a project management and build system that handles this, like Maven.
A NetBeans Maven project will have a Dependencies folder instead of a Libraries folder and if project B is properly setup and registered as a Maven project and project A is also created as a Maven project, you could Add Dependency on B to A and B would forward it's dependency information to Maven project A.
If you want to add another project as a library in netbeans right click on the libraries directory and select "Add Project", select the project you want to add. When you do this the jar file(in the dist dir) that has been built for the project you are adding will be selected and then click the "Add Project jar files" and that should add the jar file to your project. Alternatively you could select "Add Jar" instead and add the jar file yourself the way that Ravi described.
In your project folder you see a folder called Libraries , right click on that folder from there you can select your .jar file. You need not to add .jar files repeatedly after adding once to your project. You just need to Clean and Build your project whenever new files are added to .jar file.

Categories

Resources