Use snapshot library when developing a web app in eclipse - java

I develop a web application using eclipse, maven and tomcat container. My web app uses snapshot version of a Java library that I also work on. In eclipse both projects (web app and the library) are open. The library is a regular Maven/Java project, and the web app is a Dynamic Web Application.
The problem is that eclipse under Maven Dependencies displays the library project as open, and not the jar files, so when I want to debug the web app the jar of that library is not copied into the WEB-INF/lib folder of tomcat. If I use a release version of the library, eclipse displays the jar file and is copied into the WEB-INF/lib folder of tomcat.
To solve that problem I have to close the library project and it works as expected (jar copied into tomcat). Is there a way to include an open project into a dynamic web app when debugging it with tomcat under eclipse?
.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

I am not sure if it works in web projects but
<project> -> context menu -> Maven -> Disable Workspace Resolution
will stop the m2eclipse plugin to resolve dependencies in the workspace (by checking open projects). The dependencies will be requested from the (local) repository instead. Thus you have to install your library project if you want a new version to be referenced by your web project.

Related

Eclipse IDE for Java Developers 2021-06 Cannot find class paths for jars

I have built a new machine and installed a fresh version of eclipse (Eclipse IDE for Java Developers 2021-06). If I run an old project it works. If I make a new project I the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: net/crl/CRLibs/DBI
at EnvList.(EnvList.java:143)
Caused by: java.lang.ClassNotFoundException: net.crl.CRLibs.DBI
There are no errors in the code.
The build path looks like:
Line:143 is: static DBI db = new DBI();
DBI is defined in the crlibs jar.
In my old Eclipse (Oxygen) the build path looks like:
I tried adding the crlibs jar to the Classpath, but it will not let me save it (all boxes grayed out).
Now this code is copy of a template I use. The original runs just fine and its build path looks like the one from Oxygen.
If I comment out this line it will give the same error at the next library access.
It appears that the Class paths to the library are not being included.
Note The library was built with Oxygen. Do I need to rebuild it with the new version and if so will it then still work for all the code build with Oxygen.
How do I fix this?
Note:
Eclipse Java EE IDE for Web Developers.
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
And
Eclipse IDE for Java Developers (includes Incubating components)
Version: 2021-06 (4.20.0)
Build id: 20210612-2011
EDIT:
Here is the .classpath file.:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="E:/Documents and Settings/Cliff/libs/crlibs.jar" sourcepath="E:/Documents and Settings/Cliff/Libs_src/CRLibs/src/net/crl/CRLibs">
<attributes>
<attribute name="javadoc_location" value="file:/E:/Documents%20and%20Settings/Cliff/Libs_src/CRLibs/CRLibs/doc/"/>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
The path to the jar is there?
EDIT2
The command line:
In the figure below
You must delete the jar from Modulepath THEN add it to the Classpath. The JRE seems just fine in the Modulepath. Once my library is in the classpath the code works.

Can I select different .jar files in an XML .classpath file depending on what OS I am building for?

We are building a Java tool that runs on both Windows and Linux. The project is built in Eclipse. In the project we include The Standard Widget Toolkit (swt.jar). There are no common swt.jar file for both Windows and Linux, so we have to use different files, and this is what is causing the problem. Some developers are building on Windows and some on Linux, and to make it work the developer have to change the swt file to match the current building environment and this has to be done in a number of places. This is one of the .classpath files:
<?xml version="1.0" encoding="UTF-8"?>
<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.8"/>
<classpathentry combineaccessrules="false" kind="src" path="/logviewer_common"/>
<classpathentry kind="lib" path="/logviewer/swt/linux_x64/swt.jar"/>
<classpathentry kind="con" path="SWT_CONTAINER/PLATFORM"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Is there a way to add a condition that if I am building on Windows the file /logviewer/swt/win64/swt.jar is included and if I am building on Linux instead the file /logviewer/swt/linux_x64/swt.jar is included?
I have been trying to read and understand the XML tags and found that there is an <os> tag where one can specify Windows or Linux(unix), but it seems like I am not clever enough to understand if or how this can be used.
It is configured and built with Ant.
Would be very grateful for some help!

How is .classpath file in eclipse generated?

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.

Can a java .classpath refer to a .jar file within the eclipse plugin folder independant of install location?

I have an Eclipse plugin which stores its class library at \plugins\edu.wpi.first.javadev.sunspotfrcsdk_1.0.6.5\sunspotfrcsdk\lib\WPILibJ\classes.jar within the Eclipse install directory. At present, the .classpath uses an absolute path, so breaks when the project is run on another computer.
How can I make the .classpath refer to a .jar file using a path relative to the eclipse install directory?
Plugins should generally be referenced in eclipse .classpath as Libraries not Jars.
if you look at the .classpath file you'll see this distinction:
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="webdriver-tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
<classpathentry kind="lib" path="lib-new/test/hamcrest-all.jar"/>
The kind src is a source folder the kind con is a Library, and kind lib is regular jar.
You'll notice the kind="con" points to a static container for the library and is not dependent on a path. Plugins should provide this container and you can add them to your build path through project context menu
Build Path->Configure Build Path...->Add Library
Here's a screenshot:
Note that all developers will need the plugin installed for this to work.

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