While learning and exploring Java 9 from eclipse. I create a simple project in eclipse, Although when I compile the project, it prints the program's expected result but along following exception too.
Could not instrument class mymodule/App: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(Unknown Source)
at java.instrument/sun.instrument.TransformerManager.transform(Unknown Source)
at java.instrument/sun.instrument.InstrumentationImpl.transform(Unknown Source)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at java.base/sun.launcher.LauncherHelper.loadMainClass(Unknown Source)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Java code:
package mymodule;
import java.util.List;
public class App {
public static void main(String[] args) {
List<String> immutables = List.of("Food", "Water", "House");
System.out.println(immutables.get(0));
}
}
module-info.java file
module mymodule {
}
Seems like Eclipse is yet to migrate to ASM_6.0 which is completely Java 9 compatible.
On the other hand you're looking at the stacktrace which is similar to BUG#526383 and you can follow the same for updates.
Related
I have a folder(which is where I am running all commands) called learning. Inside this folder, I have two files, one is called Driver.java which is a simple main class with a simple hello world method. The other file is DriverTest.java which has this code as shown below.
import static org.junit.Assert.*;
import org.junit.Test;
public class DriverTest {
#Test
public void test() {
fail("Not yet implemented");
}
}
Apart from this I have JUnit 4.13-beta jar inside the same learning folder.
Now I open command line in windows and go to learning folder location and run this command.
javac -cp junit-4.13-beta-1.jar;hamcrest-core-2.1-rc4.jar;. *.java
It didn't give me any errors, hence it has compiled both Driver and DriverTest java files.
Now I am trying to run the JUnit test using this command.
java -cp junit-4.13-beta-1.jar;hamcrest-core-2.1-rc4.jar;. org.junit.runner.JUnitCore DriverTest
But I am getting this error:
JUnit version 4.13-beta-1
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:77)
at org.junit.runner.JUnitCommandLineParseResult.createRequest(JUnitCommandLineParseResult.java:116)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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)
... 17 more
Why is my HamCrest jar not found? Its right there in the same folder right?
You only added the current directory to the classpath for compilation. This needs to also be done for test invocation, ie. ;. in windows :. on linux
java -cp junit-4.13-beta-1.jar;. org.junit.runner.JUnitCore DriverTest
I am very new to boilerpipe and I am trying out the following basic code:
package contentExtraction;
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
public class ContentExtractor {
public static void main(String[] args) throws Exception {
final URL url = new URL(
// "http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en"
"http://www.dn.se/nyheter/vetenskap/annu-godare-choklad-med-hjalp-av-dna-teknik"
);
System.out.println(ArticleExtractor.INSTANCE.getText(url));
}
}
But I am getting the following error when trying to run the above piece of code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at contentExtraction.ContentExtractor.main(ContentExtractor.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
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)
... 16 more
I googled the error and came across this link. I thought that I was missing xercesImpl.jar in my dependencies. I included the same, still my code is giving the same error. What is the issue?
I figured the solution myself. The boilerpipe jar has further dependencies. I converted my project to maven project, included the dependency:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
When I build the above project, I can see there are actually 4 jars that are imported in Maven Dependencies folder:
boilerpipe-1.2.1.jar
nekohtml-1.9.18.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
I try to complete LTW example from AspectJ Cookbook, but it doesn't work.
I created and compiled Java class:
public class MyClass{
public void foo(int number, String name){
System.out.println("Inside of foo");
}
public static void main(String[] args) {
MyClass myObject = new MyClass();
myObject.foo(1, "Str");
}
}
it works just fine:
c:\TEMP\examples>java MyClass
Inside of foo
Then I created aspect:
public aspect HelloWorld{
pointcut callPointcut(): call(void MyClass.foo(int, String));
before() : callPointcut(){
System.out.println("Hello World from advice");
}
}
compiled it:
c:\TEMP\examples>c:\tools\aspectj1.8\bin\ajc -outjar my.jar HelloWorld.aj
C:\TEMP\examples\HelloWorld.aj:4 [warning] no match for this type name: MyClass [Xlint:invalidAbsoluteTypeName]
pointcut callPointcut(): call(void MyClass.foo(int, String));
^^^^^^^^^
[Xlint:invalidAbsoluteTypeName]
1 warning
And then try to run:
c:\TEMP\examples>java -classpath "C:\tools\aspectj1.8\lib\aspectjweaver.jar" "-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader" -Daj.class.path=. "-Daj.aspect.path=c:\TEMP\examples" MyClass
java.lang.ExceptionInInitializerError
at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
Caused by: java.lang.IllegalStateException: recursive invocation
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
at java.util.ServiceLoader.loadInstalled(Unknown Source)
at java.util.ResourceBundle.<clinit>(Unknown Source)
... 17 more
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
Caused by: java.lang.IllegalStateException: recursive invocation
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
at java.util.ServiceLoader.loadInstalled(Unknown Source)
at java.util.ResourceBundle.<clinit>(Unknown Source)
at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
I try different solutions and exception occurs only if I provide -Daj.aspect.path=c:\TEMP\examples, but as far as I understand it is because weaver will load aspect only of this option is provided. Without this option Java program works without any aspects weaved at load time.
Can you use the javaagent? I feel it is simpler than modifying the class loader:
javac MyClass.java
ajc HelloWorld.java -1.8 -outxml -d out
export CLASSPATH=.:out:$CLASSPATH
java -javaagent:$AJHOME/lib/aspectjweaver.jar MyClass
Hello World from advice
Inside of foo
The -outxml option on the ajc call is what produces the META-INF/aop-ajc.xml file in the out folder, and that is what the agent will look for to turn on weaving. (That xml file will simply list the aspects to 'turn on' and optionally some extra weaver configuration)
I am trying to run a very simple JFace program:
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class HelloSWT_JFace extends ApplicationWindow{
public HelloSWT_JFace(){
super(null);
}
protected Control createContents(Composite parent){
Text helloText = new Text(parent, SWT.CENTER);
helloText.setText("Hello SWT and JFace");
parent.pack();
return parent;
}
public static void main(String[] args) {
HelloSWT_JFace awin = new HelloSWT_JFace();
awin.setBlockOnOpen(true);
awin.open();
Display.getCurrent().dispose();
}
}
As far as I know, all the libraries are installed and the code, in Eclipse, gives me no errors. Nonetheless, when I run I get
and the long error report:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
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)
... 6 more
Does anyone know what could be causing this?
Please note; I took a look at THIS question and followed the solutions, but installing Equinox plugins did not work.
Thanks to the links Baz provided, I found the solution by making sure all the necessary Jars were added (I was missing a couple).
The necessary jars are:
org.eclipse.core.commands_<version info>.jar
org.eclipse.equinox.common_<version info>.jar
org.eclipse.jface_<version info>.jar
org.eclipse.osgi_<version info>.jar
org.eclipse.ui.workbench_<version info>.jar
More info can be found at the link Baz provided: "Identify the Required External JAR Files for SWT and JFace"
I wonder why the Game.class wont start. Here's he problem I got:
java.lang.NoClassDefFoundError: Game (wrong name: game/Game)`
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Exception in thread "main"
You will get similar error if you do mething like this:
package game;
class Game
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
without putting the compiled class file in a sub-folder called game and run it like java Game. So your Game class is in a package called game.
Please Check Your packaging structure and ensure that your class file is inside the package folder . Compile and Happy Execution ....