Adding external folder jar in to build path - eclipse

In my RCP plugin application, earlier having a folder at project level "neededJar" in which i have all external jar needed in project build
But now I want to put all jar at a common library say a lib folder in installation directory, at my workspace i added needed jar as project->build path->configure build path->add external jar it works but when I export the plugin project it is not able to resolve dependency.
I also tried to give it as class path variable but it did not work.
My classpath entry is as follow:
<classpathentry kind="var" path="MY_JAR"/>
<classpathentry kind="var" path="MY_JAR/MYClasses.jar"/>
<classpathentry kind="var" path="MY_JAR/jMYlex.jar"/>
<classpathentry kind="var" path="MY_JAR/MYsm.jar"/>
By digging i got to know, not sure about it I am missing some entry in Manifiest.MF and build properties.
Please count what are the steps that i am missing. Please suggest me through process to add external jar in plugin project
update: it is yet not answered well.

You could use a linked folder.
Create a new folder in your workspace, but open the "advanced" tab in the wizard. Chose "Link to alternate location".
Just be careful with references to folders outside your workspace, since they have a tendency to move from time to time :).

Related

Eclipse classpath container - file for defining associated jars

I have a .classpath file with entries such as
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/current-3d"/>
I can then add external user libraries to that container inside eclipse.
But which file is updated once I've done this? I.e. is there a similar xml file that says JAR's x,y + z are associated with the current-3d container?
Right I did actually find the answer, turns out it's the org.eclipse.jdt.core.prefs file, more info here Where/How does Eclipse store user libraries?
And the specific entry for the jars/user libraries is like so
org.eclipse.jdt.core.userLibrary.current-3d=<?xml version\="1.0" encoding\="UTF-8"?>\r\n<userlibrary systemlibrary\="false" version\="1">\r\n\t<archive path\="C\:/Users/pstatham/javacode/master/RunImported/3d/jgl.jar"/>\r\n</userlibrary>\r\n

Set Eclipse Build Path Libraries from Project dir

I'm using eclipse with svn and when I add some .jar files to my Build Path eclipse add the jar with the full path from the root.
I know for sure that the file will always be in a folder called lib in the same directory as my project:
for example:
~/lib
~/proj
Can I add the file taking my project's directory as a reference? Something like ../lib?
Because, right now, when somebody makes an update the Build Path needs to be changed...
Thanks a lot
under
Window > Preferences > java > Build Path > User Libraries
you can define user libraries, witch you can add to your class path. just say new type in a name (for example MY_EXTERNAL_LIB_FOO) and hit ok. Then select it (simple click) and hit add JAR..., you can then brows your jars and add the ones you want (multi select is possible)
the entry in .classpath will look something like this
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/MY_EXTERNAL_LIB_FOO"/>
this way you can abstract the location for the libs for your projects, they only need to know the name, Eclipse needs to know where the Libs for a name are located.
If you are versioning the libs too within you project then when editing the Build path hit add JARs... and not add External JARs... you will be prompted wi a list of all the project in the actual workspace, choose the onse you have in your project. the entries in .classpath will be relative to your project.
So if you have the following project layout
+ MyProject
+ src
+ lib
some_3rd_party_lib.jar
then the entry in .classpath will look like
<classpathentry kind="lib" path="lib/some_3rd_party_lib.jar"/>

Eclipse - make it use a environment variable to point to the local maven repo in the sourcepath attribute in .classpath

The Maven plugin for Eclipse is finding relevant source code for one of my project's referenced libraries in my local Maven repository and adding a sourcepath attribute to my .classpath file.
<classpathentry kind="lib" path="lib/core/guava-11.0.1.jar" sourcepath="Users/<my_user>/.m2/repository/com/google/guava/guava/11.0.1/guava-11.0.1-sources.jar">
<attributes>
<attribute name="javadoc_location" value="http://docs.guava-libraries.googlecode.com/git-history/v11.0.1/javadoc/"/>
</attributes>
</classpathentry>
The problem is that I cannot commit the .classpath file because it contains a hardcoded path to my local maven repo. Is there a way to tell Eclipse to output that using a environment variable like M2_HOME? Even if it's not automated, is there any token that I can put in there that will let it resolve the location of the source without the hard-coded path? I tried:
sourcepath="$M2_HOME/com/google/guava/guava/11.0.1/guava-11.0.1-sources.jar"
but Eclipse could not resolve the location of the source for this library after I made this change.
Any ideas?
With maven 2 you can set the M2_REPO classpath variable in Eclipse and maven eclipse:eclipse will use it automatically in your .classpath file. Details can be seen here: http://www.mkyong.com/maven/how-to-configure-m2_repo-variable-in-eclipse-ide/
We've not yet migrated to maven 3 so I am not certain, but I imagine the variable needs to be named M3_REPO for maven 3.
You're right that committing the .classpath or .project files is not a good idea.
However, in the same way that m2e added that value, as would the plugin for other users. Maven will download the files required on the PC of another user if required (i.e. not in their local repo), and give the correct sourcepath in the .classpath file.
Hope that helps!
I would add "guava-11.0.1.jar" to a maven repository and then add it as a dependency in my pom.xml. By doing this you won't have "classpathentry" tags in your .classpath file.
After that I would turn on source downloading via the m2eclipse plugin (Window->Maven and check "Download Artifact Sources"). Using sources this way does not add any .classpath file entries.

Eclipse Plug-In Dependencies Vanished

I am developing OSGi in Eclipse, and the plugin dependices has vanished for a project.
I have checked .classpath, and it seems fine:
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
I have tried starting eclipse with -clean and I have tried creating a new workspace and importing the projects into that workspace - no luck with either.
Any ideas? :)
Some strange eclipse bug. Re-edited the manifest file, and the dependencies reappeared and the project successfully compiled.
In case anyone still encounters this issue, the solution that worked for me eventually was (on Eclipse 4.3)
Delete the org.eclipse.pde.core.prefs file under the .settings folder in the plugin project
Remove/Delete the project from the workspace
Re-import the project back into the workspace
This should fix the Plug-in Dependencies entries for that project.
Hope it helps!
Check that you defined a valid target platform in Eclipse.
Go to Window -> Preferences -> Plug-in Development -> Target Platform.
When importing the plugin it was set to an empty target platform, you can verify this by first edit the selected target, then selecting the content tab of the target platform, it's empty.
I changed the Target Platform to 'Running Platform (Active)'.
This imported the necessary libs in the project, they were added to the plugin dependencies.
You can also opt to define your own custom target platform but that needs some more work and knowledge.
The .classpath file is for Java builder only. Dependencies are in META-INF/MANIFEST.MF

How to filter deployed code when exporting EAR from eclipse?

I have a basic web application (dynamic web project in eclipse) with an associated EAR project. I am trying to make sure that my junit test code stays out of the deployment EAR file.
In my web project I have a source folder called "src" and one called "test". I need to keep the .class files from the "test" source folder OUT of the EAR when I export it using eclipse.
I know this is trivial using ant but seems impossible using eclipse.. right click project and export the ear file.. the test classes are always included.
If I manually edit the .setting/org.eclipse.wst.common.component.xml file to remove the tag associated with the test folder it works but if some other developers change anything related to the build path, it gets regenerated...
Am I missing something obvious.. I've googled like crazy to no avail.. checked eclipse's docs and am at a loss..
It doesn't seem to be directly possible, which is bizarre. Here's a couple of workarounds you could try.
Note I'd move the java files from the web project to a Java project (this is probably a good practice to follow anyway). Either way create another "test" Java project and move the test sources to that project. Your test project declares the "main" Java project as a dependency so it has access to the types for testing, but isn't included in the war, so the test classes won't be deployed.
Alternatively if you want to keep the sources in one project, you can configure the test project to use linked resources. I've posted another answer that shows how you can use linked resources to share source locations across projects. With this approach the test sources still aren't on the build path for the main project, so won't be bundled in the jar, but are physically located in the project so source control is simpler.
I'm doing something similar, except with PDE, Using Eclipse 3.7.
I am deploying Eclipse/OSGi plugins/bundles, and have two java source directories: src and test
I've tweaked the contents of two eclipse project files to separate test code from the build.
.classpath:
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry export="false" kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry export="false" kind="lib" path="/thirdparty/junit/junit.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
These changes were motivated by reading this
I don't know if this will apply to your situation, but I also had to modify a build.properties file, to exclude the results of compiling 'test' from the produced jar file.
source.optimizing.jar = src/
#This doesn't contain test/ because we don't want it in the build.
bin.includes = META-INF/,\
optimizing.jar
#The junit.jar is also exluded
When I build the entire project, the test files are completely absent.