I'm developing an Eclipse plugin, and want to use some pre-compiled classes which I've put to lib/ folder in my project (so the directory structure looks like {proj_root}/lib/com/example/Required.class). Then I've added lib/ folder as class folder to project's build path. At build time all is working fine, I can import and use that classes in my code. And now the problem is, when I'm running my plugin in separate Eclipse instance I get ClassNotFoundException by my plugin refering to class from precompiled classes folder.I tried specifying my class folder in "Order and export" tab in Build path settings. Also I tried setting checkbox in plugin's build.properties GUI editor in front of lib/ folder to be included in binary build. In that case if I export my plugin to JAR I can see lib/ folder inside it, with my classfiles, but at runtime my plugin still cannot find any of classes from lib/.Can you please give me an advice on how I should tell Eclipse where to find that classes at runtime?
PS.:
I did research on stackoverflow on this problem, but all suggestions are the same: just add class folder in project's Build path.
At this point in plugin's build.properties Text editor, eclipse shows warning The class folder 'lib/' is not associated to any output library entry. and suggests to make this modification of code:
output.. = bin/,lib/. I have tried that solution but it is seems to change nothing with the problem.
It sounds very much like you have added the lib folder to the "Java Build Path" properties page of the plug-in project.
But... for plug-in projects, this does not work as these are OSGi bundles - you must include the lib folder in the PDE Editor on the "Runtime" page:
Related
I'm trying to export an Eclipse Plgug-In in Eclipse Oxygen, but I get the following errors (only 2):
The error is in one of my Java Classes, emitter1, when I use the xerces import and then the Base64 Object below, but when I compile the plug-in in the IDE in runs with no errors,
Here's an image of my projects tree:
The import and the object are being used, like I said, in the emitter1 class,
Does anyone know why this is happening and how to solve it?
Maybe I can't use referenced libraries in plug-in projects, or I have to add them in a different way? What I did was: Right-Click on Project -> Properties -> Java Build Path -> Add External Jars, and added xerces jar
Thank you!
Alexandre Jacinto
You can't use external jars in a plugin. You can only reference code in other plugins or jars which you include as part of your plugin and add to the Bundle-Classpath in the MANIFEST.MF (and also update the build.properties to include the jars in the build).
An example Bundle-Classpath from one of my plug-ins:
Bundle-ClassPath: .,
lib/jogg-0.0.7.jar,
lib/jorbis-0.0.15.jar,
lib/vorbisspi1.0.2.jar
The . is your normal code and the other entries are jars in a lib directory in the plugin project.
The build.properties would include
bin.includes = ....... other things
.,\
lib/jogg-0.0.7.jar,\
lib/jorbis-0.0.15.jar,\
lib/vorbisspi1.0.2.jar
If you use the normal plugin.xml/MANIFEST.MF/build.properties editor you define the bundle classpath on the 'Runtime' tab in the 'Classpath' section and the build.properties on the build.properties tab.
Unfortunately Eclipse doesn't check any of this when you test your plugin within Eclipse. The errors only appear in exported plugins and RCPs.
I am working on a plugin that consist of a homemade view to Eclipse.
When I run the plugin and display the classpath using System.getProperty("java.class.path")
I get this as output : D:\Programs\eclipse\plugins\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
I would like to add some .jar files for the proper functioning of my view, but I can't figure out how... I guess you can do it by adding some specifications to the MANIFEST.MF of the plugin but I don't know how to do it propely.
any ideas ?
Each Eclipse plugin has its own classpath. To use additional jars in the plugin you need to include them in the plugin.
Add your jars to the plugin directory. Usually they are put in a 'lib' directory.
Open the plugin MANIFEST.MF editor and on the 'Runtime' tab in the 'Classpath' section click the 'Add...' button and add your jars to the class path.
On the 'Build' tab of the editor make sure the 'lib' folder is include in the Binary Build section.
Your MANIFEST.MF should end up with a `Bundle-Classpath' entry that looks something like:
Bundle-ClassPath: .,
lib/jogg-0.0.7.jar,
lib/jorbis-0.0.15.jar,
lib/vorbisspi1.0.2.jar
(here I have 3 jars in a lib folder).
The build.properties file should be something like:
bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/,\
lib/jogg-0.0.7.jar,\
lib/jorbis-0.0.15.jar,\
lib/vorbisspi1.0.2.jar
For Compile time we need to add it to the Project runtime library.
For the run time you have to package the jar either in your EAR/WAR file or Load it to the Application server as a App server libraries.
Please let me know if you need further assistance on this.
The best approach I've found is to create a lib directory in your Eclipse project (where your view is contained). Place your .jar files in said lib directory.
Then using the editor on the MANIFEST.MF, you add the .jar files to the classpath. If you wish to export the packages, you then add to the Exported Packages as well.
Depending upon what you are doing, you may wish/need to also update the Build Configuration.
If you examine the MANIFEST.MF file itself, you will then see an entry for Bundle-ClassPath. It will list your entries. Here it has the standard "." for the project, a resources/ directory that we export, and a couple of .jar files.
Bundle-ClassPath: .,
resources/,
lib/aopalliance-1.0.jar,
lib/apccore-client-2.11.8.jar,
lib/cglib-nodep-2.2.2.jar,
lib/ehcache-2.10.3.jar,
...
Note that in our experience, it is also necessary to adjust the Java Build Path from the Properties of the project itself. A user commented that this step may not be necessary. We are on an older version of Eclipse due to our product, so YMMV, If needed (usually compile failures are the indicator), you then need to add, via the properties context menu on the project, the .jar files to the "Java Build Path" (you can do the same with a resources directory).
This will allow you to properly build using the .jar files.
I have two maven projects in eclipse, a jar and a war. The war has a dependency on the jar, which is resolved through workspace resolution.
The problem is that the jar has generated classes, which are added to the jar through build-helper-maven-plugin. But these classes aren't being properly resolved in the war project. For example: It auto-completes the class but keeps saying it can't be found. More importantly, when running glassfish through eclipse, I get a class not found for these classes.
If I disable workspace resolution everything works fine, but I hope to use workspace resolution. Any ideas?
EDIT:
Folder structure. The maven workspace resolved persistence project in the lower image is in the Maven Dependencies folder, essentially your seeing the top and bottom of the folder.
IDK if I am correct, but you are talking about Eclipse problems - it does not "see" generated classes right?
To fix it, you have to add generated sources directory to the eclipse's build path and it should fix your problem.
Right click on project that has generated classes->buildPath->conf
buildpath
In source tab - click add folder
Select the directory where build helper generates java files.
Generated classes will apear as additional source folder in Eclipse's project hierarchy and voila, Eclipse can autocomplete and resolve generated classes now on the same conditionstha any it would on any other class written by you in the same project by hand.
Suddenly, all my code depending on external jars doesn't work.
For example:
Jsoup.parse(str)
gives:
could not resolve type: org.jsoup.Jsoup
And i'm 100% sure that it is in the build path.
Maybe it happenned because I updated the ADT plugin and the platform tools to the latest version, but it doesn't make sense...
But it started occuring since I updated those.
So apparently eclipse doesn't compile those jars. (In code, it DOES resolve the jars types)...
Do you maybe know what is the problem?
This has nothing to do with compilation: jar's are already compiled.
You only need to add the jar to your project classpath so Eclipse will know to run java with the .jar. You can do this with "Context/Right click menu->Properties > Java Build Path > Libraries" (source). For portability I recommend placing the .jar in a subdirectory of your project. A "lib" folder in your project root (where "bin" and "src" are too) is commonly used.
Also note that to run your program you will need to add the dependency .jar to your java command, but with a little searching you can find out how to include the dependency .jar in your own combined .jar.
You have to put the libraries in /libs folder of your project (if you are using Eclipse you choose "Add JARs.." not "Add external JARs..")
I have several Maven projects converted into one Eclipse workspace. When I edit the code under Eclipse, I sometimes use CTRL+SHIFT+M combination of keys to automatically add imports to the classes from a project in my workspace. But somehow they are added like this:
import src.main.java.com.mycompany;
while to real package I wanted to import is com.mycompany.
This has to be some configuration in Eclipse to fix this but I'm confused. However, this issue is very annoying.
EDIT:
I've forgotten to mention that Eclipse files were generated using mvn eclipse:eclipse command.
Under Eclipse project seems to be configured properly. Its source folders set like this:
src/test/java
src/test/resources
src/main/java
src/main/resources
And everything under Eclipse works properly except the situation when I press CTRL+SHIFT+M keys
The standard source folder for Java projects is
./src
For imported maven projects, simply remove this folder from the list of source folders at the build path settigs. The correct source folder is
./src/main/java
In eclipse;
Remove the existing source folders first.
-right click -> menu -> build path -> remove from build path
then
Right click on the source folder.
build path -> use as source folder.
Seems like your settings are pointing to the parent of the source folder so src is recognized as package by eclipse.
It's because eclipse is not aware of the convention over configuration filestructure Maven is following. Install the M2Eclipse plugin and File > New > Other > Maven Project for new projects or for existing ones right click on your imported project on Package Explorer > Maven > Enable Dependency Management. Once successfully done, on the Package Explorer you would see your project nicely gathered following the Maven conventonal filestructure like src/main/java, src/main/resources, src/test/java and from then on you'll start seeing your package structure hierarchy like com.mysite.myproject..
First remove it. Then add it back using right click on package->build path->configure build path-> Source->Add Folder and add the entire /src/main/java tree
You've got the wrong source folders in your build path, and it's a wonder that anything works at all.
You can use either the maven-eclipse-plugin or M2Eclipse to automate getting this right, or you can manually fix the build path to call our your actual source folders, not their great-grandparents.
Non of the above worked for me. Finally I just changed the name of the scr folder to scr-java and this removed the package structure with scr as root package.