Eclipse e4 Application - ContextFactory not found when included in a plugin - java

I have a pure e4 application and would like it to work in Java 11.
I have a plugin that provides the libraries for our product to use. I've added the latest JAXB libraries to the MANIFEST.MF and .classpathof the plugin.
Plugin MANIFEST.MF
Bundle-ClassPath:
...
jakarta.activation-api-1.2.1.jar,
jakarta.xml.bind-api-2.3.2.jar,
jaxb-osgi-2.3.2.jar,
...
Export-Package:
...
com.sun.xml.bind,
com.sun.xml.bind.v2,
...
Plugin .classpath
...
<classpathentry exported="true" kind="lib" path="jakarta.activation-api-1.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="jakarta.xml.bind-api-2.3.2.jar"/>
<classpathentry exported="true" kind="lib" path="jaxb-osgi-2.3.2.jar"/>
...
Product MANIFEST.MF
Bundle-ClassPath:
...
NameOfPlugin;bundle-version="1.0.0",
...
Import-Package:
...
com.sun.xml.bind.v2,
...
Product .classpath
...
<classpathentry exported="true" kind="lib" path="jakarta.activation-api-1.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="jakarta.xml.bind-api-2.3.2.jar"/>
<classpathentry exported="true" kind="lib" path="jaxb-osgi-2.3.2.jar"/>
...
Run Configuration
I've updated the JVM options for the application.
-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory
Exception
java.util.concurrent.ExecutionException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:90)
at com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly(Uninterruptibles.java:199)
at com.google.common.cache.LocalCache$Segment.getAndRecordStats(LocalCache.java:2312)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2044)
at com.google.common.cache.LocalCache.get(LocalCache.java:3952)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3974)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4958)
at com.ci.data.reports.ReportFileManager.getAllQueryFromFile(ReportFileManager.java:81)
at com.ci.data.reports.ReportFileManager.lambda$getAllQueryFromFiles$11(ReportFileManager.java:321)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Why is it unable to find the ContextFactory class?

From the JARs you have listed, I think you have included only the JAXB APIs but not a JAXB implementation.
Remember that Java 11 broke backwards compatibility by removing JAXB entirely. You need to check whether any of the JARs on your classpath actually contain the class com.sun.xml.bind.v2.ContextFactory.
You probably need something like the org.glassfish.jaxb:jaxb-runtime JAR.

Related

Eclipse Junit: java.lang.ClassNotFoundException

I have the following problem:
I have a java project that uses gradle. The project structure is:
src
- main
-- java
-- resources
- test
-- java
-- resources
I have the following test class:
package it.main.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MainTest {
#Test
public void mainTests() {
String s = "ciao";
assertEquals(s, "ciao");
}
}
If I run the following command: gradle test everything is ok. If I try to run the mainTests method from eclipse (right click on the method, Run As, JUnit test) I have the following exception:
Class not found it.main.tests.MainTest
java.lang.ClassNotFoundException: it.main.tests.MainTest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:499)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
This is the build.gradle file:
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
compileJava {
options.fork = true
}
dependencies {
// Add all the jar dependencies from the lib folder.
compile fileTree(dir: 'src/main/webapp/WEB-INF/lib', include: ['*.jar'])
compile fileTree(dir: '//opt/jenkins/wcs_artifacts/WCS_trunk', include: ['beanstyler.jar', 'UnycoIntegrationBean.jar', 'UnycoModels.jar'])
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "5.2.0"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "1.2.0"
}
task createWCSAdminWar(type: War, dependsOn: [test, classes]) {
baseName = 'WCSAdmin'
destinationDir = file("$buildDir/dist")
}
task createUnycoAdminWar(type: War, dependsOn: [test, classes]) {
baseName = 'UnycoAdmin'
destinationDir = file("$buildDir/dist")
}
task createDists(dependsOn: [createWCSAdminWar, createUnycoAdminWar])
defaultTasks 'build'
And this is the .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoIntegrationMessages"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoModels"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/resources"/>
<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="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
Inside webapp/WEB-INF/lib/ I have the junit-4.12.jar file
Can anyone help me? Thanks

javaoctave jar file has failed in Mac OSX Eclipse

Hi I am currently using Eclipse Kepler for my java project.
I wanted to use the Octave (the open sourced MatLab) for calculation. Therefore I have tried to use the javaoctave (https://kenai.com/projects/javaoctave) to help me do the calculation in java. However, when I want to compile my code I get the following error:
Exception in thread "main" dk.ange.octave.exception.OctaveIOException: java.io.IOException: Cannot run program "octave": error=2, No such file or directory
at dk.ange.octave.exec.OctaveExec.<init>(OctaveExec.java:102)
at dk.ange.octave.OctaveEngine.<init>(OctaveEngine.java:65)
at dk.ange.octave.OctaveEngineFactory.getScriptEngine(OctaveEngineFactory.java:49)
at learn.CapabilityLearner.connectOctave(CapabilityLearner.java:72)
at learn.CapabilityLearner.connect(CapabilityLearner.java:37)
at learn.CapabilityLearner.<init>(CapabilityLearner.java:24)
at learn.capability.CapabilityMeanVarianceEquation.<init>(CapabilityMeanVarianceEquation.java:10)
at parse.basketball.runner.GetPlayerFrequency.learnSynergyGraph(GetPlayerFrequency.java:102)
at parse.basketball.runner.GetPlayerFrequency.main(GetPlayerFrequency.java:94)
Caused by: java.io.IOException: Cannot run program "octave": error=2, No such file or directory
at java.lang.ProcessBuilder.processException(ProcessBuilder.java:478)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:457)
at java.lang.Runtime.exec(Runtime.java:593)
at dk.ange.octave.exec.OctaveExec.<init>(OctaveExec.java:100)
... 8 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 10 more
This java project has been successfully run on a Windows machine with Eclipse Kepler so I think it is not the code I have that contains an error. the wiki has mentioned the error and some explanation is given. However, due to my lack of experience with programming I could not have grasped the meaning of the solutions. Can anyone help me to identify the problem and teach me how I shall fix this?
With many thanks ! :)
PS : the .classpath of the project is as followed:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="matlabcontrol-4.0.0.jar"/>
<classpathentry kind="lib" path="javaoctave-0.6.4.jar" sourcepath="javaoctave-0.6.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="commons-math-2.2.jar"/>
<classpathentry kind="lib" path="commons-logging-1.1.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
You can easily solve your problem setting up the Factory
OctaveEngineFactory factory = new OctaveEngineFactory();
factory.setOctaveProgram(new File("path_to_octave_executable"));
OctaveEngine octave = factory.getScriptEngine();
bgcode

Error when exporting a project with Log4j2 into a JAR

I'm creating a JAR file for my project that uses Log4j2. I have saved the Log4j2 jars (for CORE and API) in the 'lib' folder under the 'src' folder. Within Eclipse, I exported my project to create the JAR file and I have checked that the 'lib' folder is included/present in the JAR file.
When I run the project from within eclipse, it runs absolutely fine but when I try to execute the jar via the cmd prompt, I get the following error:
C:\Users\workspace>java -jar ConnectorClient.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at com.client.ConnectionClient.<clinit>(ConnectionClient.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
The line in my code (Line 20) causing the error is:
private static Logger logger = LogManager.getLogger(ConnectionClient.class);
It seems as if the Log4j2 jars are not being read. Can somebody be able to help me here please. I've already added the 2 jars in the project's Java Build Path as shown in the image..
My classpath file (present inside the project folder) includes the 2 jars in questions as shown:
<?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/jdk1.8.0_05"/>
<classpathentry kind="lib" path="lib/log4j-api-2.0-rc1.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.0-rc1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Any help please?
Thanks
Maybe you want to export a Runnable Jar file:
And include the required libraries:
There is a common misconception that a jar can be packaged into another jar. It just won't be available to the classloader, so you will end up with class loading exceptions.
So you either extract the dependency jar into your own jar, as described using eclipse by #PaulVargas, OR you do what 90% of people do and add your dependencies to the classpath of your jar execution:
java -classpath libs/*.jar -jar MyJar.jar
This means putting all your dependencies in a separate folder (here, libs) NOT packaged within your jar.

NoClassDefFoundError after importing an external jar

After importing JSoup, everytime the first line of Jsoup code is run, the app gives me this
09-16 16:43:22.567: E/AndroidRuntime(1085): FATAL EXCEPTION: main
09-16 16:43:22.567: E/AndroidRuntime(1085): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
09-16 16:43:22.567: E/AndroidRuntime(1085): at me.masterejzz.testapp.StartingPoint$1.onEditorAction(StartingPoint.java:55)
09-16 16:43:22.567: E/AndroidRuntime(1085): at android.widget.TextView.onEditorAction(TextView.java:4185)
09-16 16:43:22.567: E/AndroidRuntime(1085): at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
09-16 16:43:22.567: E/AndroidRuntime(1085): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:297)
09-16 16:43:22.567: E/AndroidRuntime(1085): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
09-16 16:43:22.567: E/AndroidRuntime(1085): at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 16:43:22.567: E/AndroidRuntime(1085): at android.os.Looper.loop(Looper.java:137)
09-16 16:43:22.567: E/AndroidRuntime(1085): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-16 16:43:22.567: E/AndroidRuntime(1085): at java.lang.reflect.Method.invokeNative(Native Method)
I have heavily researched this topic, and none of the fixes work for me like the lib folder thing, changing the order and export and many others.
Any help would be appreciated.
Classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry exported="true" kind="lib" path="libs/jsoup-1.7.2.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Go to Eclipse ->
right click on your Project ->
"Properties" ->
"Java Build Path" ->
"Order and Export" Tab
There check all boxes with attached jars.
Sometimes after, may need clear + refresh your project
Hope it will help you,
I had a similar NoClassDefFoundError error when adding a new jar to my JaveEE project. I followed the steps above make sure that the jar was properly included in the build path. However, I was still getting the error what done the trick for me was to remove and add the resource into the tomcat server.
- Go to Servers
- Right click on the server and select "Add and Remove"
- Pick the resource with the new jar then remove it and it
- Restart the server

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hiber nate/cfg/Configuration

I created a project in Eclipse and executed it succesfuly (It's a normal project, without Maven or Beans, really simple), I created a .jar with the project and tried to execute it but it throws the following error:
C:\Documents\wrapper-windows-x86-64-3.5.19-st\bin>java -cp QuoteHandler.jar stoc
k.view.Main
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hiber
nate/cfg/Configuration
Exception in thread "Quotes" java.lang.ExceptionInInitializerError
at stock.controller.HollidayController.<clinit>(HollidayController.java:
25)
at stock.view.MainThread.run(MainThread.java:57)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at stock.controller.HollidayController.<clinit>(HollidayController.java:
22)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
The .classpath file of the project has:
<?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/jre7"/>
<classpathentry kind="lib" path="lib/antlr-2.7.7.jar"/>
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/hibernate-commons-annotations-4.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-core-4.1.10.Final.jar" sourcepath="lib/hibernate-core-4.1.10.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-entitymanager-4.1.10.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/javassist-3.15.0-GA.jar"/>
<classpathentry kind="lib" path="lib/jboss-logging-3.1.0.GA.jar"/>
<classpathentry kind="lib" path="lib/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.20-bin.jar"/>
<classpathentry kind="lib" path="lib/org.springframework.beans_3.1.4.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/org.springframework.web_3.1.4.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/org.springframework.context_3.1.4.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/joda-time-2.2.jar"/>
<classpathentry kind="lib" path="lib/c3p0-0.9.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Checking on the Internet I modify the %CLASSPATH% variable to:
CLASSPATH = C:\Program Files\Java\jre7\lib;C:\Program Files\Java\jre7\lib\c3p0-0.9.1.jar
All the References are well configured in the Build Path of the project and it works, but when I'm executing the .jar it doesn't work (All the references are included in the jar). What am I missing?
when you specifically specify the class path when you run your program with -cp you override the default CLASSPATH os variable.
So you need to either specify all the needed classes/jars as a list in -cp, or you need to modify your CLASSPATH to have the directory of your jar. This question, Setting multiple jars in java classpath, describes setting multiple classpath elements.
Try following option from Eclipse:
File->Export
From the Wizard select Java->Runnable JAR file
Click Next
Select Launch Configuration: Select the class with main() method, if it is not available here then try to run your program once in eclipse
Export Destination: Select full path for your jar file
Library Handling: Select third one "Copy required lib..."
click on finish
Go to command prompt and change the dir to exported jar file and type
java -jar <exported_jar>.jar
One note:
In java for classpath lib/* does not resolve to all jars in directory, you have to type each and every jar entry manually.
You are trying to launch the program using command-line, the .classpath is file is for the eclipse project to maintain the list of jars pertaining to that project and has nothing to do with running the same code from command line, that's why you get the "java.lang.ClassNotFoundException"
Looking at the .classpath file, I think you project structure is like:
Proj
|
|---src
|
|---lib
So in order to run the code you can do,
For windows:
java -cp lib/*;/path/to/your/jar/QuoteHandler.jar stock.view.Main
For UNIX:
java -cp lib/*:/path/to/your/jar/QuoteHandler.jar stock.view.Main
Few things to note here:
-cp argument is ignored if the -jar option is used.
1. So you have two options, modify the manifest file to include the classpath variables
2. Add this jar too in classpath along with other jars as mentioned above, and run the main class.
Also, using -cp will basically override the values of Environment Variable for that session.
Next time again if you try the program again without -cp switch, default value (set in environment variable) of CLASSPATH will be picked.
UPDATE
If you are using this command:
java -cp lib/*;QuoteHandler.jar stock.view.Main
1. Remove quotes they add no value
2. If I look at the command above it means that, you layout is something like:
somefolder
|
|----QuoteHandler.jar
|
|----lib
| |
| |--- antlr-2.7.7.jar
| |--- dom4j-1.6.1.jar
| |--- hibernate-commons-annotations-4.0.1.Final.jar
| |--- hibernate-core-4.1.10.Final.jar
| |---...and so on (NO SUBDIRECTORIES)
Is it the same structure you are having here?
You mentioned in comments of using wildcards.The wildcards only work on JDK 6 onward . So if you JDK version is lesser than that, it might not work (and the way around it to add all the jars in path).

Categories

Resources