score:28
You can do either this way:
In the dependency you can add the other projects to your project. Right click on project -> properties -> java build path -> projects. Add your project here.
OR
Make the classes of project into jar and add it to other project
Dependencies should be added in classpath
In run time, make sure the JAR files of the referenced projects is added in class path on both the cases.
score:-1
Yes. In the Project Explorer right click on it and select Properties, there go to Java Build Path and select Projects tab. Add your other project here, now you're able to use the classes from it in your current project. But note BOTH have to be open when you run them or debug in eclipse (otherwise you will see red lines telling you a class was not found).
score:0
You can do it in 2 ways.
Export the other project to jar
and import the jar in your project.
OR
In the dependency you can add the other projects to your project. Right click on project --> properties --> java build path --> projects
. Add your project here
score:1
You have to open your project properties, then clcik on "Java Build Path" and select the tab "Projects". Add the project from which you want to import your classes and do a rebuild.
score:1
Make the classes of the project A into jar
and add it to the class path of the other project B
score:1
This works fine as long as you have imported the project containing the classes.
Assuming your using Eclipse the following steps will work:
- Right Click > Project
- Click Project Properties
- Click Java Build Path
- Click the Projects Tab
- Click the Add Button
- Select the Project
- Click OK
score:1
I had a similar problem and finally I realized that the problem was that the class in the calling project was not under src
folder, but inside another inner package. When I removed that folder and moved the file to the src
folder, everything worked.
score:3
I have done like this in my project:
ClientResponse response=WebServiceClient.invokeGRODService("document","get",documentId);
- invokeGRODService() is a method in WebServiceClient class where URL is mentioned.
- "document" is method level path,"get" is class level path and documentId is parameter to be passed as an input to other class in other project.
- invokeGRODService() is as follows:
public static ClientResponse invokeGRODService(String classLevelPath, String methodLevelPath,Object request){
> LOGGER.info("invokeGRODService()...Start");
> ClientConfig config = new DefaultClientConfig();
> Client client = Client.create(config);
> WebResource service=null;
> try{
> service = client.resource(UriBuilder.fromUri(AppProperties.getProperty(AppConstants.GROD_REST_SERVICE_URL)).build());
> }catch(PropertyNotFoundException pe){
> LOGGER.error("Error getting the--- "+pe);
> }
> try {
> ClientResponse response = service.path(classLevelPath).path(methodLevelPath).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
> request);
> if (response.getClientResponseStatus() != ClientResponse.Status.OK) {
> String errorResponse = response.getEntity(String.class);
> LOGGER.error("RECEIVED ERROR FROM WEBSERVICE.."+errorResponse);
> }
> LOGGER.info("invokeGRODService()...End");
> return response;
> } catch (Exception e) {
> LOGGER.error("Error while calling GRoD web service: ",e);
> }
> return null;
> }
- Mention your URL in "AppConstants.GROD_REST_SERVICE_URL". I have taken it from constant through AppProperties.
ClientResponse response = service.path(classLevelPath).path(methodLevelPath).type(MediaType.APPLICATION_XML).post(ClientResponse.class, request);
- If URL is correct you should get data in response object with status 200(OK).
score:13
Knowing that you using any version of Eclipse, the below steps should help you:
Step #1. Right Click => Project
Step #2. Click Project Properties
Step #3. Click on Java Build Path
Step #4. Click the Projects Tab
Step #5. Click the Add Button
Step #6. Select the Project you want to add
Step #7. Click OK button
Hopefully this help.
Source: stackoverflow.com
Related Query
- Can we call another project java class from our project in eclipse
- Can't call a class from another git project in Eclipse
- import from another java project in eclipse
- How to zip up a Java eclipse project so it can be easily unfolded onto another computer?
- How can I reference another project in Eclipse Java EE projects?
- How to correctly call my Java code from a JSP project in Eclipse
- How to call a class from another project in Eclipse?
- How can I write tests in one Eclipse project for classes from another Eclipse project?
- How can I refer to a class from another project in the same Workspace in Eclipse/Java
- Override a Java class from another project
- How to read a property file of a project from another java project in eclipse
- How to port an Eclipse Java project to another PC and compile it from Shell?
- How can i load a class from another project using ClassLoader
- Java (eclipse): How to call a int or string from another class in same project?
- How can I call a method in jar from another eclipse plugin project?
- Access classes from one project in another Java Web project in Eclipse
- Creating a Eclipse Java Project from another project, programatically
- Use files from one Java project in another project in Eclipse
- In eclipse can we generate main method for a java class from the source
- How can I run an Eclipse compiled Java class from the command line?
- Cannot import class file from Java project into another class file in the same project
- Call to class from different eclipse plugin project
- Why can my Java project call my DLLs successfully in Eclipse when I place them in JAVA_HOME\jre6\bin but failed in using java.library.path?
- Can't access class in Eclipse plugin from a Java Project
- How to run a java class in Eclipse (part of a maven project with a pom file) from cmd
- call method java from a maven project in eclipse
- How one project can reference to another in Eclipse Java
- Is there a way to make Eclipse open a hyperlinked java file from another project from the same workspace
- Eclipse - Using classes from another java project but same package for testing purposes
- Create a new java package in eclipse (apart from default package), but can not use the class from external library in the files in this new folder
More Query from same tag
- ClassCastException in android application
- Servlet 404 error - even after changing server location
- Trying to use a while or do while loop to run a basic math game with certain conditions
- Trying to connect to Sql server through Eclipse (could not find driver..i think)
- My Android App shows the google map in debug but doesn't show it when released to the market
- Why do I keep getting error while opening eclipse juno in the first time?
- Is there a way to indicate if we are exceeding a certain size limit on certain fields
- Subclipse svn:ignore
- How to delete a deleted project from Eclipse Helios?
- JUnit test on setters and getters failing
- There are no compatible JREs installed in the workspace. Add library > JRE system library...nothing
- Cannot install Subclipse plug-in in Eclipse
- Two git repositories in one working directory
- Can not run grails project. Server fails to start
- Adding image to JLabel, and displaying Labels in a GridLayout
- Eclipse Jetty Integration start.ini
- Eclipse GEF on Mac Snow Leopard
- Eclipse editor that unpackages/repackages files on open/save?
- Eclipse (IBM AST) cannot find imports to existing files
- Spring Tool Suite create new spring starter project error
- Why maven is always pointing to lower version of JRE
- Maven svn: E215004: Authentication failed and interactive prompting is disabled; see the --force-interactive option
- Android Eclipse - Button that creates another button on click
- Error While Deploying AngularJS Project which communicates with a Spring RESTful web service returning JSON data
- Dynamic Web project in Eclipse Neon not including jars from Ear APP-INF/lib
- Android- Eclipse can't find ImageButton class
- No resource found that matches the given name (@style/AppTheme)
- How to make a source attachement in eclipse?
- Cancel notification not working
- How to add 70 local jars on maven project?