Bizarre "NoClassDefFound" Error - eclipse

This one really has me stumped.
Scenario:
Windows 7 64-bit
Lotus Notes (8.5.2)
Eclipse Helios
Java 6 Update 33 (64-bit) with JDK 7
Installed JRE for the plugin project is set to use the JVM installed under Notes (that is, C:\NotesDev\Notes\jvm).
Target Platform uses the installed JRE above, and imports the framework\rcp\eclipse and framework\shared\eclipse subfolders on the Locations tab. I can see that there are a total of 713 plugins available between the two folders.
The Run Configuration shows a total of 714 plugins selected (which includes the 713 from the Target Platform, and mine). I can see that this list includes both org.eclipse.swt.win32.win32.x86_3.5.2.v34557f-RCP20100710-0200.jar and com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar.
The problem:
If I do not explicitly include the two aforementioned JAR files in my build path, the application fails to compile (trying to import org.eclipse.swt.widgets.Display and com.ibm.rcp.swt.swidgets.SToolItem).
If I include the aforementioned JAR files in the build path, the application compiles, but won't run, due to a NoClassDefFound exception.
The questions:
Why do I need to include these files in the first place? They are part of the workspace, and none of the other JAR files I'm referencing seem to need to be explicitly referenced.
Why is this failing at run time? My understanding is that NoClassDefFound occurs because the class was available at compile time, but isn't at run time. But this is occurring on the same machine. (I'm trying to debug it locally, and I've even marked the JAR files for export!)
It seems to me that if the files are listed in the Runtime Configuration's loaded plugins tab, I wouldn't have to explicitly reference them. Am I incorrect regarding this? (Please be kind! I'm admittedly not an expert at this.)
Thanks in advance.
P.S. It's worth noting that if I include the files in the build path, I can see that they are properly referenced in both MANIFEST.MF and the .CLASSPATH file.
MANIFEST.MF CONTENTS
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin
Bundle-SymbolicName: com.satuit.crm.plugin;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.satuit.crm.plugin.Activator
Bundle-Vendor: Satuit Technologies, Inc.
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.apache.axis,
org.eclipse.ui;bundle-version="3.4.2",
org.eclipse.core.runtime;bundle-version="3.4.0",
org.eclipse.ui.views;bundle-version="3.3.1",
com.ibm.rcp.jfaceex;bundle-version="6.2.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.satuit.crm.plugin,
com.satuit.crm.plugin.document,
com.satuit.crm.plugin.ui,
com.satuit.crm.webservice.agent
Bundle-ClassPath: .,
/NotesDev/Notes/framework/rcp/eclipse/plugins/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar,
/NotesDev/Notes/framework/rcp/eclipse/plugins/com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar,
/NotesDev/lib/activation-1.1.1.jar,
/NotesDev/lib/mail.jar,
/NotesDev/lib/commons-lang3-3.1.jar,
/NotesDev/lib/SatuitCRM_XML_API2.jar
** .CLASSPATH CONTENTS **
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/commons-lang3-3.1.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/activation-1.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/mail.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Workspace/lib/SatuitCRM_XML_API2.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/axispatch.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/axis.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/jaxrpc.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/saaj.jar"/>
<classpathentry exported="true" kind="lib" path="C:/NotesDev/Notes/framework/rcp/eclipse/plugins/org.apache.axis_1.4.0.20100729-1241/wsdl4j-1.5.1.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

You can also get the NoClassDefFound error when a class referenced by Display or SToolItem isn't found. The only way I know to figure out exactly which class can't be found is to run the java app with the -verbose option. You get far more logging than you ever want to see, but somewhere in all those lines of output is an error message naming the specific class that can't be found.

The OSGi MANIFEST won't accept absolute paths to jars on the system (it's for including jars within the bundle), and if you update the Java Build Path it probably won't work when it's deployed.
Fundamentally, you're writing an OSGi bundle and you have to be careful with the classpath. It looks like there are 2 different issues you have to change.
org.eclipse.swt.win32.win32.x86_3.5.2.v3557f-RCP20100710-0200.jar and com.ibm.rcp.swtex.win32_6.2.2.20100729-1241.jar are already OSGi bundles. They need to be in your target platform. Then, you need to add them to Required-Bundles, just like com.ibm.rcp.jfaceex. To be honest, they look like fragments. In that case, org.eclipse.swt.win32.win32.x86 should be picked up automatically because you consume org.eclipse.ui, which re-exports org.eclipse.swt. It might be that you need to add a Require-Bundle on com.ibm.rcp.swtex (a possible host bundle for the win32 swtex fragment)
All of those jars you've added to the Bundle-ClassPath. Are the classes you need not in packages already in your target platform? Ideally you want to consume them from existing OSGi bundles. At least org.apache.axis is already an OSGi bundle. For the rest of them, if you really need classes from those jars and they don't already exist as exported packages in your target platform, you need to either turn them into OSGi bundles and include them in your target platform or actually include them in your eclipse project, and add them to your Bundle-ClassPath from there (it'll be a project root relative path).

Well, as it turns out, the OSGI manifest will accept absolute paths on the classpath. Surprise, surprise.
Whether or not it should is another story. And what that will do to the application once it's deployed is anyone's guess. But the runtime and compile time errors have disappeared, and so far don't appear to be resurfacing.
Once again, what we considered fact and actual fact turned out to be two very different things.

Related

Glassfish 4, Eclipse IDE 2019-03 - CustomRealm: AppservPasswordLoginModule cannot be resolved to a type

I would like to implement a Custom Realm by overriding the security classes but I'm getting an error:
AppservPasswordLoginModule cannot be resolved to a type
The import com.sun.appserv cannot be resolved
I followed the steps from this tutorial: https://computingat40s.wordpress.com/how-to-create-a-custom-realm-in-glassfish-3-1-2-2/
What I did:
I created a new java project
Added a new lib folder to my project.
Copied the security.jar(also tried with security-ee.jar) from $glassfish-installation-folder\glassfish\modules to lib folder
I added this line to my .classpath file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/security.jar" />
<classpathentry kind="output" path="bin"/>
</classpath>
I also tried to add the jar to build path using Eclipse GUI
NOTES: I'm not using MAVEN, I also tried to clean the project as it was mentioned in other answers
After making this steps Eclipse throws me an arror when I want to extend MyCustomModule with AppservPasswordLoginModule:
enter image description here
UPDATE!
I found the JAR that must be added to JAVA build path: glassfish-ee-api.jar
I solved the problem by creating a new library where I copied all the JARS from $glassfish-installation-folder\glassfish\modules
Photo

Gradle/Eclipse issue when importing projects

Have been using Gradle with Eclipse on a multi-project development effort for over two years. During that time, every once in a while (maybe after changing branches too often) Eclipse gets confused. Deleting the projects (not their contents) and re-importing fixes it every time. Typically, I have needed to do this about once every two months. No big deal! Import is done within Eclipse via the Import->Gradle Project -> build model process.
I needed to do this again recently after upgrading to the latest packages. Now compilation and execution (running Unit Tests for instance) within Eclipse works fine; but debug has lost all the inter-project dependencies. I can no longer set a breakpoint on code in Project 2 and run something from Project 1 and have the source code display. Instead, I get the "Edit Source Lookup Path" window when the breakpoint is hit.
I have Eclipse Luna Release 2, version 4.4.2, Spring IDE 3.6.4.201503051146-RELEASE, and Gradle IDE 3.6.4.201503050952-RELEASE. My gradle wrapper is version 2.3.6, and I am on a Mac OS X 10.10.3
The previous .classpath files looked like:
<classpath>
<classpathentry kind="src" output="build/classes/main" path="src/generated/java"/>
<classpathentry kind="src" output="build/classes/main" path="src/main/java"/>
<classpathentry kind="src" output="build/resources/main" path="src/main/resources"/>
<classpathentry kind="src" output="build/classes/test" path="src/test/java"/>
<classpathentry kind="src" output="build/resources/test" path="src/test/resources"/>
<classpathentry exported="true" kind="src" path="/proj1.main"/>
<classpathentry exported="true" kind="src" path="/proj2.main"/>
<classpathentry exported="true" kind="src" path="/proj3.main"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
<classpathentry kind="output" path="target"/>
which has three dependent projects then show up on the Java Build Path, Projects tab. Now, none show up but the projects appear under Gradle Dependencies on the Libraries tab (so compiling and running still works).
I imported the same way I have for over two years, so that is not it. Additionally, there are some new options on the Preferences->Gradle tab. I tried with "Remap Jars to Gradle Projects" and "Use Custom Tooling Model).
Does anyone know how to make it work the way it has been working? I really do not want to generate the eclipse files from the command line.
try cleanEclipse and also check the .bin directory and see if the class files are there as this is how gradle plugin use to debug.
Hope that helps.

Build Spring Roo / Export maven project with Eclipse Export -> Runnable JAR file

I have Maven project created with Spring roo in STS 2.5.1.RELEASE (It is Eclipse 3.6.1 + Spring tools + m2eclipse). I have second simple Java project on build path. Everything is working ok within Eclipse.
Now the problem is to build. I cannot do so with maven, because it also requires that referenced project is maven project. For referenced project I just use Eclipse Export -> Runnable JAR file to export and generate ant file for next build.
Doing so for first project, I get runtime error, even though META-INF/spring/applicationContext.xml is both is .jar and in the folder next to .jar
2011-02-19 13:58:39,135-org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/applicationContext.xml]
2011-02-19 13:58:39,405-org.springframework.core.io.support.PathMatchingResourcePatternResolver - Cannot search for matching files underneath URL [rsrc:com/company/test/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [rsrc:com/company/test/] cannot be resolved to absolute file path because it does not reside in the file system: rsrc:com/company/test/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
Referenced project is under heavy development, and I cannot move, refactor it or change its nature.
Maven project with Spring roo is parallel version to be developed.
How to build maven project with included eclipse project?
Example.
Project /RooInheritanceMaven has project /RooInheritanceJava on its (eclipse) build path.
.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="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<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.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/RooInheritanceJava"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
It is incompatibility between Eclipse Export to Executable JAR and Spring.
To be more exact it is
org.springframework.core.io.support.PathMatchingResourcePatternResolver
Similar provlem was before. see
#SPR-3815 Classloader problem - Spring Projects Issue Tracker
try
jar -tf PersonApp.jar >PersonApp.jar.txt
The solution is to extract .classes and all stuff from jar into folder
jar xf PersonApp.jar
and run as
set CLASSPATH=D:\TEMP\KDF.MSSQL\antlr-2.7.6.jar;D:\TEMP\KDF.MSSQL\aopalliance-1.0.jar; <... all jar dependecies listed>
java com/company/PersonApp
Look at onejar-maven-plugin http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/
Use the Roo command
perform package
to get your application bundled - so that you can deploy it into your own container.

precedence of persistence.xml in hibernate project

I have an eclipse project with several jars for JPA / Hibernate. One of tham contains a META-INF/persistence.xml and I want to override that by defining my own persistence.xml. So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but everytime it seems jar/META-INF/persistence.xml gets picked up.
I also tried editing .classpath file of eclipse projects and moved up classpathentry path="bin" higher up than the library included but still its not picking up my persistence.xml
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/rules"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="DROOLS/Drools"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/drools"/>
</classpath>
In the tutorial I read:
You will need to override these
defaults if you want to change them,
by adding your own persistence.xml in
your classpath, preceding the default
one in drools-persistence-jpa.jar
So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but every time it seems jar/META-INF/persistence.xml gets picked up.
The persistence.xml should be located under META-INF/persistence.xml so the first attempt won't work. And when I look at your .classpath file, I don't see src as source path so the second attempt won't work either.
Try src/main/java/META-INF/persistence.xml instead.
Actually, your project layout really looks like a Maven layout and with Maven, resources typically go to src/main/resources or src/test/resources. But since you didn't mention what tutorial you're following, I can't confirm if this applies here.
Anyway, my suggestion should work.

Specific JRE name (which might not be the same on other computers) stored in meta-data for Eclipse Ganymede WTP project

Problem overview:
When using Eclipse Ganymede with the Web Tools Platform the project gets dependent on the exact JRE name I use. The name might be different on other developers machines, how is this problem best solved so that many developers may work together on the project?
Detailed problem description:
I'm using Eclipse Ganymede and Web Tools Platform (as it's part of Eclipse IDE for Java EE Developers) and I have created a Dynamic Web Project.
I have a single JRE installed, the Sun JRE for Java SE 6. In Eclipse I can choose:
Window / Preferences / Java / Installed JREs. And I can see a list of JRE's, each row has Name, Location and Type columns.
I only have one entry in the list, it has: Name=java-6-sun-1.6.0.07 Location=/usr/lib/jvm/java-6-sun-1.6.0.07 *Type=*Standard VM.
The problem is that the name of my JRE is specified in two Eclipse project meta-data files, they are .classpath and .settings/org.eclipse.jst.common.project.facet.core.prefs.
I want to check my project into version control for other developers to check out and work on, but I don't think that I can be sure that they have a JRE with the same exact name as I do.
Contents of the offending files:
.classpath: (The second to last classpathentry is the offending tag.)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&confs=*">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-sun-1.6.0.07"/>
<classpathentry kind="output" path="target/eclipse/classes"/>
</classpath>
.settings/org.eclipse.jst.common.project.facet.core.prefs:
#Mon Feb 02 13:29:53 CET 2009
classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType\:\:java-6-sun-1.6.0.07/owners=jst.java\:6.0
eclipse.preferences.version=1
What's the best way to check in this project and let other developers check it out and run/change it?
Select the execution environment instead of the JRE to use. To do so, got to your project -> Properties -> Java Build Path -> Libraries. Select the "JRE System Library" element, click "Edit..." and select the Execution Environment of your choice (probably "JavaSE-1.6" for your example).
The .classpath file will then contain an entry like this:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>