How to reflect another project's class info - java

there are two projects in eclipse! how to reflect one class in other project? I put other project's class path into system's property. but still popup class not found exception. Is there any good solution for it?
System.out.println(System.getProperty("java.class.path"));
System.getProperties().put("java.class.path",
System.getProperty("java.class.path") +
";C:\\Users\\fu.jian\\workspace\\Study\\bin");
System.out.println(System.getProperty("java.class.path"));
Class<?> forName2 = Class.forName("study.Activator");
System.out.println(forName2);

Right click the project to bring up the context menu.
Build Path->Configure Build Path
Under the Java Build Path dialog, select the Projects tab and add the project.

Try to add the project B to classpath of project A by:
In Eclipse click on project A -> mouse right click and select Properties -> Select Java Build Path -> Select Projects tab -> Click on Add... and check project B
The problem will be resolved inside Eclipse, if you use external tools for compilation and building the project - your problem will still appear.
You can export the project B as jar and copy the jar into the project A libs. This way you won't depend on Eclipse.

Related

Eclipse Launched Maven project not using classes in the \target folder

I have a project which I am converting from plain Java to Maven.
I used the "Configure -> Convert to Maven Project" option in eclipse.
I removed all jars in the classpath and referenced them in my POM file and built the project
My new classes are built in project/target but when I launch from eclipse, (using the original launcher) , the old classes are in project\bin folder are used.
How do I reconfigure this to use the correct classes ?
Seems that the configuration for output files in eclipse has not change.
Try to change the output of generated files in eclipse manually:
Right click in project -> Properties.
Select "Java build path" and tab "Sources".
At bottom you have a field named "Default output folder". Change it for: <your-project>/target/classes
For example:
Hope it works.

Using jar file in another project

I have one jar file, named pwd.jar and I want to use that in another project named sample.
How can I do that? What are all the steps I should perform?
Note: I am using Eclipse IDE
Right click your project-> properties->Java Build Path -> Libraries tab -> Add External jar, and browse your jar
Cheers

why this eclipse error showing and what should be the solution for it

Missing library: xdoclet-1.2.1.jar. Select the home directory for XDoclet. 1.2.1
why this eclipse error showing and what should be the solution for it alz
It is causing possibly because that jar is not added to your project build path. Follow this steps:
Right click on project(in the package explorer)
-> Buid Path
-> Configure Build Path
-> Java Build Path
-> Libraries tab
-> Add JARs button
Then locate the folder where the jar resides. You can filter your search by typing *.jar in the search field. And then click ok.
I downloaded the xdoclet-lib-1.2.3.zip file from:
http://sourceforge.net/projects/xdoclet/files/xdoclet/1.2.3/
unziped it to its folder name, xdoclet-1.2.3, and then from the Eclipse (I was using 4.5) preferences JavaEE -> XDoclet tab selected the Version 1.2.3 and then the Browse button to the xdoclet-1.2.3 folder. Apply and OK and Eclipse error goes away.
Saying all that, I suspect you don't really need it unless you know that you are using xdoclet. If that's the case and it was intentionally left out then the error message should be fixed in Eclipse. I only went around fixing it because of the message.
If have maven version of the project, can also try by updating the project. I also had this XDoclet. 1.2.1.jar complaint, which got resolved once I update the project.
Right Click Project > Maven > Update Project ... > Check the projects > OK.
Please add maven dependency in your project . Steps are -
1- Right Click on Project
2- select configure build path
3- select library tab
4- add library and select Maven Dependencies
5- apply and Apply and Close .

Including a Jar in Android App

I want to include a jar into my Android package.
Unfortunately, I can't get it to work. I followed several explanations, such as this one, but I still get NoClassDefFoundErrors - at runtime, building, compiling, installing the project worked without errors.
Most answers seem to be outdated. How do I solve this issue using the current Eclipse, ADT and Android versions? Adding them to the Java Build Path like in plain Java projects didn't help.
All help appreciated.
What I have tried
Putting them into a folder and including into the project [Screenshot]
Put the jar in a folder entitled 'libs' (should be in the root of your project. Then add it to the java build path.
If that doesn't work try this:
Your Project -> right click -> Import -> File System -> yourjar.jar
Your Project -> right click -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.ja
Add your jars to libs folder. Automatically add's those JARs to your compile-time build path. More importantly, it will put the contents of the JARs into your APK file, so they will be part of your run-time build path.
You two things and the error will be fixed
Right click on Project-->Select Properties-->Go to Java Build Path--> Select 3rd tab from top i.e "Libraries" -->Click Add Jar--> Select your Jar
Right click on Project-->Select Properties-->Go to Java Build Path--> Select 4th tab from top i.e "Order and Export" --> Select(chekbox) your Jar.
For more help check this link

Eclipse - Importing your own library

Okay, hopefully this is quick and easy.
I have two separate java projects, 'Library' and 'Project', and I have a class in 'Project' that wants to implement a method found in 'Library'. I am looking for some kind of 'import' call to make at the top of my 'Project' class, to make the methods found in 'Library' accessible in that project.
How would I do that?
On another note, this 'Library' project only exists because I want to use a number of classes of my own to supplement the the usual java libraries (java.util, java.io, etc...). Is there a way I can add my java project to my java libraries? (ie. 'import java.Library.className;')
Thanks,
Jonathan
Just have "Project" reference your "Library", on windows the process is (using menu / tab names)
1. Go to: Project -> Properties -> Java Build Path -> Projects
2. Client Add...
3. Select your "Library" project from the list
4. Click Ok
5. Click the other Ok
Now your done and you can use import for classes in your "Library"
There are several ways:
A. Import source files
Right click your project in the project explorer
select
Properties-->Java Build Path
Click on the Source tab and the Link Source button and add the root folder containing Library and click Finish
Now click on the Projects tab and click the Add button to add your 'Library'. Click Ok and you're done
B. Import Jar
When you compile your eclipse project it creates a jar for your project in the 'Build' subfolder of the root directory of your project. To import that in you current project:
Again Right click your project in the project explorer
Select Properties-->Java build Path
Click on the Libraries tab and click Add External JARs. Navigate to the folder containing Library.jar and click Finish and click Ok
You should now be able to import your names from your Library Project

Categories