This question already has answers here:
Unsupported major.minor version 51.0 error after moving from IntelliJ IDEA JBoss to MyEclipse Tomcat
(3 answers)
Closed 7 years ago.
This is my simple Scala-Spark object created in IntelliJ IDE using SBT project (part of the code was taken from here).
package test
import org.apache.spark.mllib.tree.RandomForest
import org.apache.spark.mllib.tree.model.RandomForestModel
import org.apache.spark.mllib.util.MLUtils
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
object Test {
val conf = new SparkConf()
.setMaster("local[2]")
.setAppName("CountingSheep")
val sc = new SparkContext(conf)
def main(args: Array[String]) {
// Load and parse the data file.
val data = MLUtils.loadLibSVMFile(sc, "data/adalone.txt")
// Split the data into training and test sets (30% held out for testing)
val splits = data.randomSplit(Array(0.7, 0.3))
val (trainingData, testData) = (splits(0), splits(1))
// Train a RandomForest model.
// Empty categoricalFeaturesInfo indicates all features are continuous.
val numClasses = 2
val categoricalFeaturesInfo = Map[Int, Int]()
val numTrees = 3 // Use more in practice.
val featureSubsetStrategy = "auto" // Let the algorithm choose.
val impurity = "variance"
val maxDepth = 4
val maxBins = 32
val model = RandomForest.trainRegressor(trainingData, categoricalFeaturesInfo,
numTrees, featureSubsetStrategy, impurity, maxDepth, maxBins)
// Evaluate model on test instances and compute test error
val labelsAndPredictions = testData.map { point =>
val prediction = model.predict(point.features)
(point.label, prediction)
}
val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean()
println("Test Mean Squared Error = " + testMSE)
println("Learned regression forest model:\n" + model.toDebugString)
// Save and load model
model.save(sc, "myModelPath")
val sameModel = RandomForestModel.load(sc, "myModelPath")
}
}
The project was successfully compiled, however when I run it the following error appears (see below). It says Unable to load native-hadoop library for your platform.
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
15/11/25 12:04:44 INFO SparkContext: Running Spark version 1.5.1
15/11/25 12:04:49 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/spark/network/shuffle/ShuffleClient : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.apache.spark.SparkContext.createSparkEnv(SparkContext.scala:277)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:450)
at test.Test$.<init>(Test.scala:13)
at test.Test$.<clinit>(Test.scala)
at test.Test.main(Test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Process finished with exit code 1
UPDATE:
The problem was solved after adding the following line of code inside the main loop of my Scala object:
System.setProperty("hadoop.home.dir", "D:\\SOFTWARE\\BIGDATA\\hadoop-common-2.2.0-bin-master\\")
Related
The same code works of JOOQ inside psvm but not inside junit tests.
public static void main(String[] args) {
InsertSetMoreStep<Record> query = DSL.using(SQLDialect.MYSQL)
.insertInto(table("TABLE_NAME"))
.set(field("FIELD"), "field");
System.out.println("query : " + query.getSQL());
}
#Test
public void tt() {
InsertSetMoreStep<Record> query = DSL.using(SQLDialect.MYSQL)
.insertInto(table("TABLE_NAME"))
.set(field("FIELD"), "field");
System.out.println("query : " + query.getSQL());
}
Running the test gives the stack over flow exception:
LClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
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)
What is the reason and how to fix the test?
This might actually be a real stackoverflow. In this case you can fix it by increasing the stack size with the parameter:
-Xss4m
Try of an explanation: JOOQ generates java classes from database structure as much as I understand. If JOOQ creates a lot of nested classes, which is very well possible for some database designs, the classloader loads those inner classes recursively which might end in a stack overflow because it's resource intense.
I don't really know JOOQ and I can't reproduce it but it would be nice to see a real stackoverflow :-)
I have this Java class:
public class SortAlgorithms {
public static void main(String... args) {
String out = "";
int vec1[] = readFile(args[0]);
out = out + write(vec1);
out = out + "=== INSERTION SORT ===\n";
insertionSort(vec1, vec1.length);
out = out + write(vec1) + "\n";
...
}
...
}
And I deploy it on other machine at my Boinc platform. There is a bash script to run this class:
#!/bin/sh
export JAVA_HOME="/usr/java/jdk1.6.0_34/"
export PATH=${JAVA_HOME}/bin:${PATH}
java SortAlgorithms 10 "output.txt" > saida.txt
And I receive this error:
<stderr_txt>
Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 1014198118 in class file SortAlgorithms
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: SortAlgorithms. Program will exit.
</stderr_txt>
Does anyone know what is happening?
Thnaks in advance.
Felipe
Your class file was not copied properly. It starts with string '<sof' which is definitely not a java bytecode start.
Looking at the Java API:
file is malformed or otherwise cannot be interpreted as a class file.
I believe that you need to compile your Java file on the machine which will be running the code.
While both maxkar and user1773630's answers seem right, it does sound like a .class file wasn't transferred properly. Compare checksums, or make a .jar?
If you've got jdk's with differing major versions installed, there can be class compatibility issues as well, which can cause a similar error.
I am working on Netbeans. I added a library selenium-java-2.31.0. But it shows exception.
I added all the libraries on which this library is dependent.
I follow this link to add library in netbeans.
My code :-
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public static void main(String[] args) throws IOException, URISyntaxException {
String url1 = "http://www.jabong.com/giordano-P6868-Black-Analog-Watch-183702.html";
Document doc1 = Jsoup.connect(url1).get();
WebDriver driver = new FirefoxDriver();
driver.get(url1);
Elements tag_list = doc1.getAllElements();
for( Element tag1 : tag_list ) {
Point point=driver.findElement(By.id(tag1.id())).getLocation();
System.out.println("X Position : " + point.x);
System.out.println("Y Position : " + point.y);
}
}
Exception
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Help me in solving this problem. Why this exception throws?
Edit No. 1
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:89)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:79)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:67)
at org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:260)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 11 more
Java Result: 1
Edit no.2
Now I moved to maven, by thinking it downloads all the dependent libraries. But now it shows diffrerent error.
Edit No. 3
As it shows some problem with firefox, I replaced firefox with Chrome.
This time previous error is removed. But a new comes in picture. Please see this.
Edit no. 4
Edit No. 5
Now I shifted to firefox again, and gets given page, but it stucks then. Why ?
Below is the error snapshot that I got.
I believe the problem you are seeing at this point is due to you passing in driver.get("url1");
I think you mean to be passing in driver.get(url1); (Notice no quotation marks)
To expand on it a little bit, the reason it is throwing the malformed uri exception is that the uri being passed in (url1) does not contain any protocol (http/https).
I think you could have created a maven project which will solve your dependency problem related to the selenium.
I have downloaded dom4j-1.6.1 and added it to java's build path. I am also familiar with java.lang.NoClassDefFoundError: org/saxpath/SAXPathException but I keep getting an exception.
Enclosed a snippet:
public class Parser {
public static void parse(final String path) throws Exception {
final SAXReader reader = new SAXReader();
final Document document = reader.read(new File(path).toURI().toURL());
if (document == null) return;
List list = document.selectNodes("/");
for (Object o : list)
System.out.println(o);
}
}
When I run it, I get the following stack trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:164)
at Parser.parse(Parser.java:15)
at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 5 more
Any clue what causes the error?
The Exception:
java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
Maybe you forgot to include the jaxen.jar in your Java build's path.
For more specific instructions on using SAXReader to parse some XML and loop through the nodes:
https://stackoverflow.com/a/24959790/445131
Found out the solution. I had to download and include jaxen in java's build path.
I've just started using Spock to write tests for my Java project. First I had some trouble figuring out how to compare floats with an accepted diff (like the delta parameter in JUnit's assertEquals).
I haven't found any other way to do this than either using the methods in JUnit's Assert class, except using the closeTo matcher that appears to be bundled with Spock. Still, I'm unable to make it work.
If I try making a test with closeTo, I end up with the following error.
Am I missing a dependency, doing it wrong, or what?
import static spock.util.matcher.HamcrestMatchers.closeTo
import spock.lang.Specification
class MatcherTest extends Specification {
def "test closeTo"() {
expect:
1.9d closeTo(2, 0.5)
}
}
java.lang.NoClassDefFoundError: org/hamcrest/TypeSafeMatcher
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at spock.util.matcher.HamcrestMatchers.closeTo(HamcrestMatchers.groovy:47)
You are missing org.hamcrest:hamcrest-core:1.2, which is referenced from the spock-core POM.