remove absolute dependency path from `.classpath`; relative path doesn't work - java

I am not a Java programmer.
I did some Java programming in the past but nothing big.
There is one tool which I use, written in Java which I want to improve.
I got the sources of the tool.
I want to make a small change
(in how it parses input files, to add support for a different file format)
then compile the tool
upload updates to repository
end of story.
But first I have to be able to compile the original project.
I opened the project in Visual Studio Code.
I got errors
Project 'UVW' is missing required library: 'D:\xyz-workspace\java\_libraries\jfreechart-1.0.19\lib\jcommon-1.0.23.jar'
Project 'UVW' is missing required library: 'D:\xyz-workspace\java\_libraries\jfreechart-1.0.19\lib\jfreechart-1.0.19.jar'
Project 'UVW' is missing required library: 'D:\xyz-workspace\java\_libraries\gson-2.2.2.jar'
The project cannot be built until build path errors are resolved
Great,
the guy who did the tool added dependency to libraries on his own computer.
(here I replaced the project name with UVW and the author's name with xyz for privacy).
I check .classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry exported="true" kind="lib" path="D:/xyz-workspace/java/_libraries/jfreechart-1.0.19/lib/jcommon-1.0.23.jar"/>
<classpathentry exported="true" kind="lib" path="D:/xyz-workspace/java/_libraries/jfreechart-1.0.19/lib/jfreechart-1.0.19.jar" sourcepath="D:/xyz-workspace/java/_libraries/jfreechart-1.0.19/source">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="D:/xyz-workspace/java/_libraries/jfreechart-1.0.19/source"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="D:/xyz-workspace/java/_libraries/gson-2.2.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
So in the project directory I simply create the xyz-workspace, I replicate the structure and put there the missing libraries.
Then I edit the paths to be relative:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry exported="true" kind="lib" path="./xyz-workspace/java/_libraries/jfreechart-1.0.19/lib/jcommon-1.0.23.jar"/>
<classpathentry exported="true" kind="lib" path="./xyz-workspace/java/_libraries/jfreechart-1.0.19/lib/jfreechart-1.0.19.jar" sourcepath="./xyz-workspace/java/_libraries/jfreechart-1.0.19/source">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="D:/xyz-workspace/java/_libraries/jfreechart-1.0.19/source"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="./xyz-workspace/java/_libraries/gson-2.2.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Ok,
but this still fails:
Project 'UVW' is missing required library: 'xyz-workspace\java\_libraries\jfreechart-1.0.19\lib\jcommon-1.0.23.jar'
Project 'UVW' is missing required library: 'xyz-workspace\java\_libraries\jfreechart-1.0.19\lib\jfreechart-1.0.19.jar'
Project 'UVW' is missing required library: 'xyz-workspace\java\_libraries\gson-2.2.2.jar'
The project cannot be built until build path errors are resolved
even though the paths are correct.
I tried to look online for how to do it correctly but found irrelevant results only.
I don't accept the situation that I replace the path on his computer with the absolute path on my computer.
I want the project be self dependent only, with all dependencies inside.
I don't know how to achieve it.

Apparently, I downloaded wrong version of the project.
In the new version, the libraries were already present in _libraries subdirectory.
The .classpath still contained absolute path to the directory inside the project.
But thus time editing it worked:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="_libraries/gson-2.2.2.jar"/>
<classpathentry kind="lib" path="_libraries/ini4j-0.5.4.jar"/>
<classpathentry kind="lib" path="_libraries/jfreechart-1.0.19/lib/jcommon-1.0.23.jar"/>
<classpathentry kind="lib" path="_libraries/jfreechart-1.0.19/lib/jfreechart-1.0.19.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
The difference seems to be exported="true" from my original example.
This is an incomplete answer because I achieved the goal, I can compile the project without absolute path dependencies but I still don't understand everything.

Related

Eclipse: The .classpath containsa a library that will not be available during continuous integration

I get this error even though the jar file, osgi.core-4.0.1.jar is there in my local .bnd folder.
Eclipse: The .classpath containsa a library that will not be available during continuous integration: C:/Users/UserName/.bnd/cache/https%3A%2F%2Fraw.githubusercontent.com%2Fbndtools%2Fbundle-hub%2Fmaster%2Fosgi.core/osgi.core-4.0.1.jar
The error is on line 1 (<?xml version="1.0" encoding="UTF-8"?>), of the .classpath in my project's main API (com.mycompany.test.api)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="src" output="bin_test" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="lib" path="C:/Users/UserName/.bnd/cache/https%3A%2F%2Fraw.githubusercontent.com%2Fbndtools%2Fbundle-hub%2Fmaster%2Fosgi.core/osgi.core-4.0.1.jar" sourcepath="C:/Users/UserName/.bnd/cache/https%3A%2F%2Fraw.githubusercontent.com%2Fbndtools%2Fbundle-hub%2Fmaster%2Fosgi.core/osgi.core-4.0.1.jar">
<attributes>
<attribute name="bsn" value="osgi.core"/>
<attribute name="type" value="REPO"/>
<attribute name="project" value="org.example.impls"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
What could be the problem? Thank you all in a advance.
When using Bndtools, you do not edit the .classpath file to add jars to compile path. Instead edit the bnd.bnd file and add the jar to the -buildpath. Bndtools will then have Bnd read the bnd.bnd file and use the -buildpath and -testpath information to populate the aQute.bnd.classpath.container classpath container.

Source Folder 'folder1' in project 'ProjectA' cannot output to distinct source folder 'folder2' in Eclipse

I am getting this error in some projects in my workspace.
I have tried using Luna and Juno version of eclipse but there are errors is still in there in both versions of eclipse
Content of .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="folder1"/>
<classpathentry kind="src" path="folder2"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/WebSphere v6.1 JRE"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.ast.st.runtime.runtimeTarget.v61/was.base.v61"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/hibernate"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/log4j"/>
<classpathentry kind="src" path="/ProjectB"/>
<classpathentry kind="src" path="/ProjectC"/>
<classpathentry combineaccessrules="false" kind="src" path="/ProjectD"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="folder2"/>
</classpath>
There are no build path errors in ProjectB, ProjectC, ProjectD
There is no proper solution
You can change that issue from error to warning in project preferences.
Under Project Properties->Java Compiler->Building
Make Sure Enable Project Specific settings is checked, Under Build Path Problems,
change Output location overlaps source location from Error to Warning/Ignore.
You can also find some related discussion on the issue over here
I did get a solution on this issue:
There is a specification of which particular folder cannot be output at the time of creating the project. I renamed that folder to .old closing eclipse and , also tried deleting it as it was a sample folder.
If its a folder which is not that important rename that folder after closing eclipse and retry.
This would fix the problem.
For me the solution was to add this line
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore
to .settings/org.eclipse.jdt.core.prefs
You have to remove that the distinct source folder 'folder2' from the src path
GO to project build path
go to source tab
select the folder2 src entry
remove it

Use Eclipse classpath variable to replace absolute "sourcepath" path?

I would like to use an Eclipse classpath variable to resolve the attached source JAR file for a library in my classpath. This is the contents of my current ".classpath" file in Elcipse (Indigo):
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/ApacheCommons/commons-logging.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Spring-WS/spring-ws-1.5.8-all.jar"/>
<!-- [other entries] -->
<classpathentry kind="output" path="bin"/>
</classpath>
When I now add a source JAR file for "spring-ws-1.5.8-all.jar", the ".classpath" files contents is:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/ApacheCommons/commons-logging.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Spring-WS/spring-ws-1.5.8-all.jar"
sourcepath="D:/dev/sources/spring-ws-1.5.8-sources.jar"/>
<!-- [other entries] -->
<classpathentry kind="output" path="bin"/>
</classpath>
As you can see, Eclipse added the "sourcepath" attribute to the "classpathentry" element with an absolute path.
Now my idea is to replace the absolute path with the classpath variable "SOURCE_PATH", which is correctly set to "D:/dev/sources".
(Please, don't ask why we have this setup or suggest we must change it; it is an old project and we are unfortunately not able/allowed to change the build structure).
I tried
sourcepath="SOURCE_PATH/spring-ws-1.5.8-sources.jar"
as well as
sourcepath="${SOURCE_PATH}/spring-ws-1.5.8-sources.jar"
but both variants do not work.
I seems, that I either use the wrong syntax or I don't understand the concept of classpath variables. Maybe the classpath variable can't be used for the "sourcepath" attribute?
Thanks a lot for your help!
I might not understand your question completely but it sounds like you added your jar file with an absolute path to begin with. Instead add it with a classpath variable.
Use the Project properties, select Java Build Path option. Then click on the Libraries tab. Then Add Variable.... If you haven't created your SOURCE_PATH classpath variable yet, you can do it from here by clicking the Configure Variables... button (just a shortcut to the proper workspace preference setting). Once configured you should see your SOURCE_PATH class path variable in the box at the top. You can click on it extend to Extend... it to a subfolder or a jar file.
Using Tod's answer above, if you have lots of jars in lots of projects, you may find it easier to edit the .classpath files directly. Using a Java Build Path variable in .classpath changes the reference from:
<classpathentry kind="lib" path="/full/pathTo/Jar.jar"/>
to:
<classpathentry kind="var" path="NEW_PATH_VARIABLE/Jar.jar"/>
You could use a symbolic link. Windows also supports paths starting with /. This is drive dependent. Try cd / on the Command Prompt to verify.

Files and Folders appear in Eclipse inside the "Referenced Libraries" category. How to prevent this behavior?

I've inherited an Eclipse project in which a lot of the data is in the "Referenced Libraries" category, although for all good purposes they show up just as regular files / directories in the file system. Adding new files to the project yields a similar result -- they'll get thrown into the "Referenced Libraries" category.
I'd like to turn this weirdo-project into something more akin to the usual Eclipse java project experience, having Flasji's contents inside src/. How?
Edit ##:
Here are my .classpath file's contents as requested:
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="alloy4.2-rc.jar"/>
<classpathentry kind="lib" path="asm-2.2.3.jar"/>
<classpathentry kind="lib" path="bsh-2.0b4.jar"/>
<classpathentry kind="lib" path="commons-io-2.3.jar"/>
<classpathentry kind="lib" path="congu.jar"/>
<classpathentry kind="lib" path="Gent java6.jar"/>
<classpathentry kind="lib" path="junit-4.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
To get rid if these visually, open your MANIFEST.MF and in the editor click on the third tab "Runtime" on that editor page there is a classpath section and you will see the jars there, if you remove them in the editor your classpath will get auto updated and the referenced libraries will no longer exist.

Eclipse - Setting .classpath file for existing project

I have a java project. The working folder from someone else's Eclipse project (It was a Repast Simphony project I think).
In my eclipse I created a new Java project and told it to use the existing code. So it seems to have brought in all the code.
However after loading the project I get this error:
Project 'My Project' is missing required Java project: 'Weka 3-7'
It has a .classpath file with these contents:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Weka-3-7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
What I've tried so far:
I installed Weka 3-7. Then I updated the .classpath file to say the following and reloaded the project.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="C|/Program Files/Weka-3-7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
But now I get the error message:
Project 'My Project' is missing required source folder: 'C|/Program Files/Weka-3-7'
Please help. I'm stuck.
You want to use the context menu: My Project::(right mouse click)::Build Path::Configure Build path. This gives you the option to add/remove projects, Jars, source folders etc., what erver you need to provide those classes that your project references. You can get the same effect by hacking the .classpath manually, but you have to know very well what you're doing. Always use the frontend unless it absolutely can't do what you need.

Categories