Every time I try to build a basic example program for using LWJGL controllers, it crashes. Here's the code:
package com.czipperz.blogspot.tests.controllers;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;
/**
* Created by Chris on 10/23/2014.
*/
public class Main {
//left joystick x and y
private float x, y,
//right joystick x and y. Like the commas?
rx, ry;
//This Controller object MUST BE org.lwjgl.input.Controller NOT net.java.games.input.Controller
private Controller c;
private boolean start;
public static final int BUTTON_A = 1, BUTTON_B = 2, BUTTON_X = 3, BUTTON_Y = 4,
BUTTON_LEFT_BUMPER = 5, BUTTON_RIGHT_BUMPER = 6, BUTTON_SELECT = 7, BUTTON_START = 8,
//When you PRESS the joysticks (click)
BUTTON_LEFT_JOYSTICK = 9, BUTTON_RIGHT_JOYSTICK = 10;
public static void main(String[] args) {
new Main();
}
public Main() {
//Says, find controllers and store them in the Controllers class to JInput. Dont worry bout it.
try {
Controllers.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
// Gets you a shiny "new" controller instance.
// Think of index like you would think of an array.
c = Controllers.getController(0);
//Sets "deadband"
float dead = .06f;
c.setXAxisDeadZone(dead);
c.setYAxisDeadZone(dead);
c.setRXAxisDeadZone(dead);
c.setRYAxisDeadZone(dead);
//Using the controller requires you to call the poll() function to receive new data.
c.poll();
x = c.getXAxisValue();
y = c.getYAxisValue();
rx = c.getRXAxisValue();
ry = c.getRYAxisDeadZone();
//NOTE: getZAxisValue(), getRZAxisValue(), getZAxisDeadZone(), getRZAxisDeadZone() DO NOT WORK
//DPAD = POV
float povx = c.getPovX();
float povy = c.getPovY();
boolean lbumper = c.isButtonPressed(BUTTON_LEFT_BUMPER);
}
}
The problem is that every time I build, this is the log: (Sorry I just can't hit space that many times)
"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Users\Chris\workspace\Controllers\out\production\Controllers;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lzma.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\jinput.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_test.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl-debug.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\asm-debug-all.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util_applet.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\AppleJavaExtensions.jar;C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.czipperz.blogspot.tests.controllers.Main
WARNING: Found unknown Windows version: Windows 8.1
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init> (DirectAndRawInputEnvironmentPlugin.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.lwjgl.input.Controllers.getController(Controllers.java:116)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:38)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported
Process finished with exit code 1
I know this thread is old, but for people who are searching for the solution.
The answer is, you have to include the native libs to your project. For the use of jinput.jar you have to include following libs:
jinput-dx8.dll
jinput-dx8_64.dll
jinput-raw.dll
jinput-raw_64.dll
You can download the natives here DOWNLOAD.
You will get a jar-file. Unzip the file with winrar to get the dll-files.
Now go to project and open the context menu with a click on the right mouse button -> Build Path -> Configure Build Path -> Choose the Libraries tab -> Click on the little arrow next to the jinput.jar to expand the view -> Make a double click with the left mouse button on Native library location -> Choose the directory of the dll-files.
Confirm the dialogs and try to run your program again.
In LWJGL there is a "native/" folder containing the respective native libraries for each platform/OS. Just choose your platform and set java.library.path to that directory.
This is your problem.
First Step:
Create a folder and rename it to LWGJL_New then in that folder create two other folders and rename the first on libs and the second one natives.
Now go to the LWGJL library that you have downloaded. Copy the jar files to LWGJL_New/libs. Then go to the LWGJL library that you have downloaded, in it, there is a folder containing respective native libraries for each platform/OS.
Choose one of them that you need and copy it to LWGJL_New/natives.
Second step:
Go to the module settings of your project(F4) then click library.Click add sign(+).Click on java. Now find the LWGJL_New folder and in it click on the jar folder and click ok. Then Click on Apply and ok.
Third step:
Now if you run your project you will occur that problem, So go to the Edit Configuration part
Then in VM options write this:
-Djava.library.path="***"
Instead of star signs write the address of the native folder that we have just created.
For example ->
D:\LWGJL_New\natives\windwos
D:\LWGJL_New\natives\linux
Then click on OK.
Then run your project.
Related
I want to export my Java project to a standalone Jar or exe file. I use blueJ as an IDE and I use following libraries: GLOOP, JOGL and GlueGen (aswell as pi4j). Running the program in the IDE itself works flawlessly, however when I export the program as a .jar file and wrap it into an exe with Launch4j I get following error:
Catched IllegalArgumentException: No Jar name in <jar:file:/C:/Users/neche/Desktop/UfoSpiel.exe!/com/jogamp/common/os/Platform.class>, got <UfoSpiel.exe>, while TempJarCache.bootstrapNativeLib() of null (null + null)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at GLOOP.GLRenderer.<init>(GLRenderer.java:90)
at GLOOP.GLKamera.<init>(GLKamera.java:49)
at UfoSzene.main(UfoSzene.java:14)
I use the Operating system Windows 64bit and BLuej version 414
I have googled a lot but never found someone who had the same problem or used the same OS or IDE.
It would be amazing if anyone of you could help.
Here is the main thread code:
import GLOOP.*;
public class UfoSzene
{
public static void main(String[] args)
{
GLKamera kamera;
GLLicht licht;
GLBoden weltall;
UfoSpiel ufoSpiel = new UfoSpiel();
Punkte punkteStand = new Punkte();
weltall = new GLBoden("Weltall.jpg");
kamera = new GLKamera(800,800);
kamera.setzePosition(2000,3001,20);
kamera.setzeBlickpunkt(2000,0,0);
licht = new GLLicht();
ufoSpiel.start();
punkteStand.start();
}
}
Thanks in advance!
I have a problem running the below java code outside of the eclipse compiler. Inside the compiler it works fine, but after exporting as a runnable jar I get an InvocationTargetException. I believe it is relevant to the dll files but after reading other solutions here and tryinging to implement them the problem remained unresolved. So my question is it possible to configure eclipse, through code or settings, to export the program correctly?
Relevant Code
BTW C:\Program Files\Tesseract-OCR contains tessdata, gsdll64.dll, liblept170.dll, libtesseract303.dll
Maven Dependencies are tess4j, junit, ghost4j
public Bot() {
System.setProperty("jna.library.path", "C:/Program Files/Tesseract-OCR");
ocr2 = new Tesseract();
ocr2.setDatapath("C:/Program Files/Tesseract-OCR");
initLists();
System.out.println(scan(0,0,500,500));
}
public String scan(int x, int y, int x2, int y2) {
BufferedImage i = rob.getScreen(x, y, x2, y2);
i = toBufferedImage(i.getScaledInstance(i.getWidth()*2, i.getHeight() *2, Image.SCALE_SMOOTH));
try {
return ocr2.doOCR(i).trim();
} catch (TesseractException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
Error
C:\Users\Blue\Desktop>java -jar bot.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:78)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:40)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:237)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:221)
at debug.Bot.scan(Bot.java:480)
at debug.Bot.<init>(Bot.java:53)
at debug.Bot.main(Bot.java:24)
... 5 more
C:\Users\Blue\Desktop>pause
Press any key to continue . . .
In case anyone has a similar issue what I did was copy the 3 .dll files into my System32 folder. I then got an issue with image.io, which the site had plenty of answers for. My personal solution was exporting the jar as my code and a separate folder for the libraries.
This question already has answers here:
How to use "cd" command using Java runtime?
(8 answers)
Closed 9 years ago.
I am trying to run a java file using the terminal but from java. Meaning, I'll run the command using java.
I am trying to execute the command 'cd /Users/apple/Documents/Documents/workspace/UserTesting/src ' that redirects to the following directory and then execute the command 'ls' that lists all the files in the current directory
I am using this method to run the Java file 'NewFile.java'
try {
String line;
Process p = Runtime.getRuntime().exec( "cd /Users/apple/Documents/Documents/workspace/UserTesting/src" );
Process p2 = Runtime.getRuntime().exec( "ls" );
BufferedReader in = new BufferedReader(
new InputStreamReader(p2.getInputStream()) );
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
catch (Exception e) {
// ...
}
The output
Directly using the terminal -> It gives 'NewFile.java'
Using this method using Java -> It always give 'bin' and 'src' for whatever command given to p2
Here are several trials
Apples-MacBook-Pro:~ apple$ cd
/Users/apple/Documents/Documents/workspace/UserTesting/src
Apples-MacBook-Pro:src apple$ java NewFile 5 90 35 45 150 3
Reichweite---- nach blase art
3 5 35 45 90 150
Apples-MacBook-Pro:src apple$ java /Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile
Exception in thread "main" java.lang.NoClassDefFoundError:
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile
Caused by: java.lang.ClassNotFoundException:
.Users.apple.Documents.Documents.workspace.UserTesting.src.NewFile at
java.net.URLClassLoader$1.run(URLClassLoader.java:202) 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)
Apples-MacBook-Pro:src apple$ java
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile.java
Exception in thread "main" java.lang.NoClassDefFoundError:
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile/java
Caused by: java.lang.ClassNotFoundException:
.Users.apple.Documents.Documents.workspace.UserTesting.src.NewFile.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 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)
Apples-MacBook-Pro:src apple$
Blockquote
So, it seems the problem you're having is that you don't understand why you get different results when you invoke the program in different ways.
Here's what's going on: Runtime.geRuntime().exec() creates a new process, which is a child of the parent. Every process has its own working directory; when you fork a new process, it inherits the working directory of the parent. Invoking cd will then change the working directory of the current process (and this is a shell builtin, but ignore that for now and I'll get to it later).
So what you're doing is this:
Parent
-> create child 1 -> change working directory of child 1
-> create child 2 -> invoke "ls"
Note that child 2 will inherit the working directory of its parent. It won't know anything about the working directory of child 1. So depending on the working directory of the process that is invoking this method (in your case, either the terminal or...I don't know, your JDK install?) you will get different results.
If you want the same results every time, you could do something like this:
Process p = Runtime.getRuntime().exec( "ls /Users/apple/Documents/Documents/workspace/UserTesting/src" );
And if you want to be able to exec your program from anywhere, just use the full path:
Process p = Runtime.getRuntime().exec( "java /Users/apple/Documents/Documents/workspace/UserTesting/NewFile" );
(assuming, of course, that you have already used javac to build NewFile.class in that directory, and that you have the right permissions to execute it.)
Re: cd, as I mentioned before this is a command that's built into your shell. When you invoke the command using exec in this way, it is likely failing. You can check on that by reading standard error using the getErrorStream() method of Process.
I am new to pig.. and am trying to write a udf function.
So basically here is the problem statement.
I have a dummy data like this..
user_id, movie_id, date_time_stamp
So what I am trying to do is this.
if the transaction is between
9 am and 11 am --> breakfast
and so on
So here is my pig script
REGISTER path/myudfs.jar
in = LOAD 'path/input' USING
PigStorage('\\u001') AS (user:long,movie:long, time:chararray);
result = foreach in GENERATE myudfs.time(time);
STORE result INTO 'path/output/time' using PigStorage(',');
Now myudf.jar java code is like this
public class time extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String) input.get(0) ;
DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
Date date = df.parse(time);
String timeOfDay = getTimeOfDay(date);
return timeOfDay;
} catch (ParseException e) {
//how will I handle when df.parse(time) fails and throws ParseException?
//maybe:
return null;
}
}
So it takes in the tuple and returns a string... (I am new to java also..)
After this i try to run this script as
pig -f time.pig
It returns an error
2012-11-12 08:33:08,214 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
hadoop file system at: maprfs:///
2012-11-12 08:33:08,353 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
map-reduce job tracker at: maprfs:///
2012-11-12 08:33:08,767 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1069:
Problem resolving class version numbers for class myudfs.time
Some one posted on pig mailing list is that my PIG_CLASSPATH is not set and that i should point it to /path/hadoop/conf
I did that.. so now $echo PIG_CLASSPATH --> /path/hadoop/conf
But i get the same error
Please advise.
Thanks
Edit 1: On looking into the log, the error trace is:
Caused by: java.lang.UnsupportedClassVersionError: myudfs/time : 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 java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:427)
... 27 more
is this like a java issue?
To find the jar version, open the jar using winzip (or similar) and look for manifest.mf. There should be a line in there that says 'Created-By' and this will give the version of java that was used to build the jar.
This needs to be older or equal to the version of java you are using to build your app. If you are doing this at the command line type:
java -version
or in eclipse go to
project(menu) > properties (menu item) > java build path (in list) > libraries (tab)
and take a look at the version that you are using for the JDK/JRE (you may be able to tell this from the directory, if not then go to that directory and do java -version).
Chances are you'll need to update the version of java you have in eclipse.
My lecturer didn't provide us with the .java files for a tutorial. My question is, how would i use his class files in my eclipse project, and defeat the following error?
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: lec/utils/InputReader
at randomIt.main(randomIt.java:17)
Caused by: java.lang.ClassNotFoundException: lec.utils.InputReader
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)
... 1 more
Here is my code:
import java.util.Random;
import lec/utils.InputReader;
public class randomIt {
public static void main(String[] args) {
Random generator = new Random();
InputReader myReader = new InputReader();
//Pick a number randomly between 1 and 10!
int number = generator.nextInt(10)+1;
//Ask user to guess...!
System.out.println("Take a guess (1 to 10)");
if (number == myReader.readInt()){
System.out.println("You win");
}
else {
System.out.println("It was " + number + ", tough Luck");
}
}
And here is my Folder Structure:
Random /
*/ bin
* / lec / utils /InputReader
* / src / randomIt.java
Note: his class file is "InputReader.class"
I've had a play with Eclipse to work this one out. Give the following a go:
Create the following directory structure (your desktop will do) classes/lec/utils
Place the InputReader class file in the utils directory.
Remove any references you have to InputReader you currently have in your build path.
Using (right click on project) Properties->Java Build Path->Libraries select the 'Add external class folder' and select the 'classes' folder you created on your desktop and click OK.
Now in the 'Referenced Libraries' in the project folder you should have one called 'classes' and a package path under that called 'lec.utils' which contains the InputReader class.
You can use that class using 'import lec.utils.InputReader' in you own class.
Hope that Helps.
In the project configuration menu, there is a "Build Path->Configure Build Path" menu item. Within that, there is an option to add an "external class folder". Put all the provided class files in a folder, and add that folder to the build path.
You should make the following changes
Modify your randomIt class to have following include line (no lecs/ )
import utils.InputReader
Modify the filename as rnadmIt.java (and not randomit.java) . The class name and fie name has to be exactly same. Also per Sun convention the class should start with a capital letter
$ cd Random
$ javac -classpath ./lec src/randomIt.java