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.
Related
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.
I have downloaded the jdt-ls as language server and configured as described here https://lsp.readthedocs.io/en/latest/#java
My project has source code which is in 'src/main' but sublime text (or jdt-ls) seems to assume that the source code lies in the root folder, i.e. every java file has a "wrong" package name. Is there a configuration for projects?
I found the solution. In the root of the project there must exist a .classpath file. Here is my file for example:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main" output="bin/src/main"/>
<classpathentry kind="src" path="src/test" output="bin/src/test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
...
</classpath>
I've a java project in the eclipse which has a .classpath file as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/generated/java"/>
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
.......
<classpathentry kind="output" path="target/classes"/>
How does this file gets generated? Can I edit this file?
I want a certificate file to be added to the project in path target/test-classes. Where do I configure that?
My understanding is the target/test-classes folder gets generated after the mvn clean install. So I think there should be some place where I can configure what all I need in the target folder. Do I need to configure it in pom.xml ?
The .classpath file reflects the content of all the settings that you apply manually to your BUILD PATH setup within your project.
In other words: while using the eclipse UI to setup the BUILD PATH, all that information goes into the .classpath file.
And it is perfectly possible to stop eclipse and make changes to that file within your preferred editor; then restart eclipse, probably do a full refresh; and (unless you messed up) the changes should be visible when opening your BUILD PATH settings again.
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
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.