ZipException thrown when using jogl in eclipse - java

This is Eclipse project build path:
files in project:
rob#work:~/git/thegame$ ll lib/linux32/
total 708
drwxr-xr-x 2 rob rob 4096 Mar 22 02:37 ./
drwxr-xr-x 4 rob rob 4096 Mar 22 02:23 ../
-rw-r--r-- 1 rob rob 8704 Mar 10 14:00 libgluegen-rt.so
-rw-r--r-- 1 rob rob 666380 Mar 11 03:22 libjogl_desktop.so
-rw-r--r-- 1 rob rob 5944 Mar 11 03:22 libnativewindow_awt.so
-rw-r--r-- 1 rob rob 26604 Mar 11 03:22 libnativewindow_x11.so
rob#work:~/git/thegame$ ll jar/
total 3308
drwxr-xr-x 3 rob rob 4096 Mar 22 02:28 ./
drwxr-xr-x 8 rob rob 4096 Mar 22 02:22 ../
-rw-r--r-- 1 rob rob 289171 Mar 10 14:00 gluegen-rt.jar
drwxr-xr-x 4 rob rob 4096 Mar 22 02:28 javadocs/
-rw-r--r-- 1 rob rob 3082066 Mar 11 03:23 jogl-all.jar
Error when trying to execute application:
Catched ZipException: error in opening zip file, while addNativeJarLibsImpl(classFromJavaJar class com.jogamp.common.os.Platform, classJarURI jar:file:/home/rob/git/thegame/jar/gluegen-rt.jar!/com/jogamp/common/os/Platform.class, nativeJarBaseName gluegen-rt-natives-linux-i586.jar): [ file:/home/rob/git/thegame/jar/gluegen-rt.jar -> file:/home/rob/git/thegame/jar/ ] + gluegen-rt-natives-linux-i586.jar -> slim: jar:file:/home/rob/git/thegame/jar/gluegen-rt-natives-linux-i586.jar!/
Catched ZipException: error in opening zip file, while addNativeJarLibsImpl(classFromJavaJar class jogamp.nativewindow.NWJNILibLoader, classJarURI jar:file:/home/rob/git/thegame/jar/jogl-all.jar!/jogamp/nativewindow/NWJNILibLoader.class, nativeJarBaseName jogl-all-natives-linux-i586.jar): [ file:/home/rob/git/thegame/jar/jogl-all.jar -> file:/home/rob/git/thegame/jar/ ] + jogl-all-natives-linux-i586.jar -> slim: jar:file:/home/rob/git/thegame/jar/jogl-all-natives-linux-i586.jar!/
Catched IOException: TempJarCache: addNativeLibs: jar:file:/home/rob/git/thegame/jar/jogl-all-natives-linux-i586.jar!/, previous load attempt failed, while addNativeJarLibsImpl(classFromJavaJar class jogamp.nativewindow.NWJNILibLoader, classJarURI jar:file:/home/rob/git/thegame/jar/jogl-all.jar!/jogamp/nativewindow/NWJNILibLoader.class, nativeJarBaseName jogl-all-natives-linux-i586.jar): [ file:/home/rob/git/thegame/jar/jogl-all.jar -> file:/home/rob/git/thegame/jar/ ] + jogl-all-natives-linux-i586.jar -> slim: jar:file:/home/rob/git/thegame/jar/jogl-all-natives-linux-i586.jar!/
Catched IOException: TempJarCache: addNativeLibs: jar:file:/home/rob/git/thegame/jar/jogl-all-natives-linux-i586.jar!/, previous load attempt failed, while addNativeJarLibsImpl(classFromJavaJar class jogamp.nativewindow.NWJNILibLoader, classJarURI jar:file:/home/rob/git/thegame/jar/jogl-all.jar!/jogamp/nativewindow/NWJNILibLoader.class, nativeJarBaseName jogl-all-natives-linux-i586.jar): [ file:/home/rob/git/thegame/jar/jogl-all.jar -> file:/home/rob/git/thegame/jar/ ] + jogl-all-natives-linux-i586.jar -> slim: jar:file:/home/rob/git/thegame/jar/jogl-all-natives-linux-i586.jar!/
Main.java
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
public class Main
{
public static void main(String[] args)
{
// setup OpenGL Version 2
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);
// The canvas is the widget that's drawn in the JFrame
GLCanvas glcanvas = new GLCanvas(capabilities);
glcanvas.addGLEventListener(new Renderer());
glcanvas.setSize( 300, 300 );
JFrame frame = new JFrame( "Hello World" );
frame.getContentPane().add( glcanvas);
// shutdown the program on windows close event
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
frame.setSize( frame.getContentPane().getPreferredSize() );
frame.setVisible( true );
}
}

When you download the JARs directly, some web browsers might wrap it into a ZIP file for "security" reasons. Rather download the 7z archive here and take the JARs it contains. You should follow these detailed instructions, it should work in Eclipse.
I remind you that the separated native libraries are no longer required in JOGL 2, rather use the JARs containing the native libraries, it is a lot less error prone, just put them into the same directory than the Java libraries relying on them (jogl-all.jar and gluegen-rt.jar).

Related

java.lang.NoSuchMethodError: accessibilityHitTest

I am getting this error on my M1 Mac. I am running a simple GUI program in Eclipse for a class and getting the error: "Bad JNI lookup accessibilityHitTest" followed by 32 lines of red messages and "Exception in thread "AppKit Thread" java.lang.NoSuchMethodError: accessibilityHitTest". I installed Java OpenJDK 17.0.1 through Homebrew, which is the up-to-date version according to homebrew. I do not know how to program in Java and this is my first class learning the language so I am a bit over my head at the moment, but this is the in-class example code that is supposed to be very simple so I am beyond confused as to why this is happening. Thank you to anyone that can provide any help in this situation!
This is what I get from the console window:
2023-02-12 07:50:17.847 java[10456:90865] Bad JNI lookup accessibilityHitTest
2023-02-12 07:50:17.849 java[10456:90865] (
0 libawt_lwawt.dylib 0x000000010dcfc7d1 -[JavaComponentAccessibility accessibilityHitTest:withEnv:] + 153
1 libawt_lwawt.dylib 0x000000010dcad7e2 -[AWTView accessibilityHitTest:] + 179
2 AppKit 0x00007ff81322ff47 -[NSWindow(NSWindowAccessibility) accessibilityHitTest:] + 302
3 AppKit 0x00007ff812cfe5ad -[NSApplication(NSApplicationAccessibility) accessibilityHitTest:] + 285
4 AppKit 0x00007ff812cbf46b CopyElementAtPosition + 138
5 HIServices 0x00007ff8150cb505 _AXXMIGCopyElementAtPosition + 402
6 HIServices 0x00007ff8150ed194 _XCopyElementAtPosition + 355
7 HIServices 0x00007ff8150aa5a9 mshMIGPerform + 182
8 CoreFoundation 0x00007ff80f8483f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
9 CoreFoundation 0x00007ff80f848337 __CFRunLoopDoSource1 + 536
10 CoreFoundation 0x00007ff80f846fb6 __CFRunLoopRun + 2749
11 CoreFoundation 0x00007ff80f845e7f CFRunLoopRunSpecific + 560
12 HIToolbox 0x00007ff8196d8766 RunCurrentEventLoopInMode + 292
13 HIToolbox 0x00007ff8196d8576 ReceiveNextEventCommon + 679
14 HIToolbox 0x00007ff8196d82b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
15 AppKit 0x00007ff8128d1293 _DPSNextEvent + 909
16 AppKit 0x00007ff8128d0114 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
17 libosxapp.dylib 0x000000010d920653 -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 121
18 AppKit 0x00007ff8128c2757 -[NSApplication run] + 586
19 libosxapp.dylib 0x000000010d920431 +[NSApplicationAWT runAWTLoopWithApp:] + 165
20 libawt_lwawt.dylib 0x000000010dd047a1 +[AWTStarter starter:headless:] + 496
21 libosxapp.dylib 0x000000010d921f73 +[ThreadUtilities invokeBlockCopy:] + 15
22 Foundation 0x00007ff8105fd190 __NSThreadPerformPerform + 177
23 CoreFoundation 0x00007ff80f847ed1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x00007ff80f847e80 __CFRunLoopDoSource0 + 157
25 CoreFoundation 0x00007ff80f847c4e __CFRunLoopDoSources0 + 212
26 CoreFoundation 0x00007ff80f8468a8 __CFRunLoopRun + 943
27 CoreFoundation 0x00007ff80f845e7f CFRunLoopRunSpecific + 560
28 libjli.dylib 0x000000010d3a989d CreateExecutionEnvironment + 381
29 libjli.dylib 0x000000010d3a5b45 JLI_Launch + 1253
30 java 0x0000000104dd1c15 main + 363
31 dyld 0x0000000205073310 start + 2432
)
Exception in thread "AppKit Thread" java.lang.NoSuchMethodError: accessibilityHitTest
Hello from the actionPerformed() method!
The button has been pressed.
Below is the code I am trying to get to work. It does launch a basic GUI with all three fields but gives me the above-mentioned error whenever I press the button or type into the text box. Also, for some weird reason, the button does not show up as red, but the text box is highlighted in yellow. The java.awt.Color library appears to be working because it is correct for the text box but no matter what I do to get the button to show up in a color it remains a white background. The color chosen is arbitrary and all works for the text box but nothing whatsoever with the button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyFirstGUI implements ActionListener
{
public static void main(String[] args)
{
new MyFirstGUI(); // load self!
}
JFrame window = new JFrame("This is my first GUI program");
JButton button = new JButton("Push me!");
JTextField textField = new JTextField("Enter data here and press ENTER.");
JTextArea textArea = new JTextArea("Info presented to user here.");
public MyFirstGUI() // CONSTRUCTOR (called by the "new" loader)
{
System.out.println("Hi from MyFirstGUI constructor!");
// Build the GUI
window.getContentPane().add(button, "North"); // top area
window.getContentPane().add(textArea,"Center");// middle area
window.getContentPane().add(textField,"South");// bottom area
window.setLocation(500,0); // x,y in "pixels" y=0 is top of window
window.setSize(500,500); // x,y
button.setBackground(Color.red);
textField.setBackground(Color.yellow);
textArea.setEditable(false); // keep cursor out
window.setVisible(true); // show it!
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(this); // call me when pushed!
textField.addActionListener(this);// call me when ENTER key!
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == button)
{
System.out.println("Button was pushed!");
}
if (ae.getSource() == textField)
{
System.out.println("TextField had data entry!");
String input = textField.getText();
textField.setText(""); // clear!
textArea.setText(input);
}
}
}
I have updated every possible piece of software and compared this to what I get on my Intel-based Mac. The issue is mostly solved using all the same software on that computer so this leads me to believe there is an issue running OpenJDK Java 17.0.1 on M1 Macs.
Possible complications to consider:
Is it that I am using an M1 Mac? This is what I think is the main concern…
If I run this on my old 2016 intel Mac running macOS Monterey 12.6.3 (the newest it can run) I can get it to run the GUI without error (but the red button still shows up white).
How can I get this to run properly on my M1 Mac?!? It is nice that I can get it running on my old laptop but it doesn't help solve the issue.
My professor is ancient and is probably using an older version of Java, if this is the case is there’d reason an older version of java would cause this problem?
This is just a question, I have no way of testing this.
Is this something to do with my software versions?
I updated to MacOS 13.2 Ventura and have updated home-brew, java, and eclipse. I do not think this is the issue but I am using pretty basic java software and simple code so I am not sure how many issues there could be.
Is it something to do with Eclipse?
I tested this by running the application in terminal and it acted exactly the same. The correct information displays on the GUI but no red button and the same error is happening.

write logs to oldest file in directory

I want to do some tweaks to my logging for my application...
I would like some help to enhance what I have below in main method:
public static void main(String[] args) {
try {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Handler h = new FileHandler("../logs/MyLogFile_"
+ sdf.format(date) + ".log", true);
h.setFormatter(new SingleLineFormatter());
h.setLevel(Level.ALL);
logger.setUseParentHandlers(false);
logger.addHandler(h);
}
//...
}
It creates a log file with date stamp everytime I run the application. But I want to achieve something like this in my Unix Directory:
-rw-r--r-- 1 r787848 dev 45271 Feb 4 11:31 MyLogFile.log.06
-rw-r--r-- 1 r787848 dev 45308 Feb 5 11:36 MyLogFile.log.05
-rw-r--r-- 1 r787848 dev 44336 Feb 6 06:50 MyLogFile.log.04
-rw-r--r-- 1 r787848 dev 44379 Feb 7 08:41 MyLogFile.log.03
-rw-r--r-- 1 r787848 dev 44409 Feb 10 08:45 MyLogFile.log.02
-rw-r--r-- 1 r787848 dev 44446 Feb 11 12:36 MyLogFile.log.01
I want to define a set of lets say 6 log files to capture logging of daily run of the application. When it comes to logging, I want the application to write to the log file that is oldest, so in the above instance, running the application on Feb 12 08:45 should clear MyLogFile.log.06 and write fresh for feb 12.
How can this be achieved with java.util.logging on top of what I have. Unfortunately, I am not able to configure log4j properties and want to use java.util.logging only.
The only close approximation is to do the following:
Handler h = new FileHandler("../logs/MyLogFile_"
+ sdf.format(date) + ".log", Integer.MAX_VALUE, 6, false);
See: JDK-6350749 - Enhance FileHandler to have Daily Log Rotation capabilities.

Why FileNotFoundException is thrown while it exists on linux

This is the first time i have encounter such problem with file access by Java on linux. The problem is just like the header says - FileNotFoundException is thrown when file actually exists. Moreover application with same configuration (props.txt file) runs like it should on windows.
Let me provide a little bit of console output
datasu#dedi2392:~/netcrawler/dkpto$ ls -l
total 20
-rwxrw-rw- 1 datasu datasu 114 Aug 7 15:53 autoupdate
drwxr-xr-x 4 datasu datasu 4096 Aug 8 11:57 data
drwxr-xr-x 2 datasu datasu 4096 Aug 8 11:57 log
-rw-rw-rw- 1 datasu datasu 32 Aug 8 12:44 props.txt
-rwxrw-rw- 1 datasu datasu 126 Aug 8 12:55 propsUpdate
datasu#dedi2392:~/netcrawler/dkpto$ ./propsUpdate
Parent: /usr/home/datasu/netcrawler/dkpto
1# -> propsUpdate
2# -> autoupdate
3# -> props.txt
4# -> data
5# -> log
(No such file or directory)ava.io.FileNotFoundException: /usr/home/datasu/netcrawler/dkpto/props.txt
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at netcrawler.Autoupdater.readProperties(Autoupdater.java:71)
at netcrawler.Autoupdater.start(Autoupdater.java:54)
at netcrawler.Autoupdater.main(Autoupdater.java:47)
datasu#dedi2392:~/netcrawler/dkpto$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
datasu#dedi2392:~/netcrawler/dkpto$
and here is Java code responsible for generating that output (at least after calling ./propsUpdate)
private void readProperties(String args) throws FileNotFoundException, IOException {
System.out.println("Parent: " + new File(args).getAbsoluteFile().getParentFile().getAbsolutePath());
CommonTools.PrintArray(new File(args).getAbsoluteFile().getParentFile().list());
properties.load(new FileInputStream(new File(args).getAbsoluteFile())); // this line throws the exception
stageNumber = Integer.parseInt(properties.getProperty(PROP_STAGE_NUMBER_KEY, "0"));
}
So why the props.txt file is not found when it is actually there ?
The string "args" probably has a nonprinting character at the end, like a space. You could use String.trim() to remove such characters before using that variable.
Is your home folder really this path?
/usr/home/datasu
/home/datasu is where it normally is on linux.
Also, try changing that line to this:
properties.load(new FileInputStream(new File(args));
If you're calling that as ./propsUpdate ./props.txt that will work from the current working directory.

Sequence Files in Hadoop

How are these sequence files generated ? I saw a link about sequence file here,
http://wiki.apache.org/hadoop/SequenceFile
Are these written using default Java serializer ? and How do I read a sequence file ?
Sequence files are generated by MapReduce tasks and and can be used as common format to transfer data between MapReduce jobs.
You can read them in the following manner:
Configuration config = new Configuration();
Path path = new Path(PATH_TO_YOUR_FILE);
SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(config), path, config);
WritableComparable key = (WritableComparable) reader.getKeyClass().newInstance();
Writable value = (Writable) reader.getValueClass().newInstance();
while (reader.next(key, value))
// perform some operating
reader.close();
Also you can generate sequence files by yourself using SequenceFile.Writer.
The classes used in the example are the following:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
And are contained within the hadoop-core maven dependency:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
Thanks to Lev Khomich's answer, my problem has been solved.
However, the solution has been deprecated for a while and the new API offers more features and also easy to use.
Check out the source code of hadoop.io.SequenceFile, click here:
Configuration config = new Configuration();
Path path = new Path("/Users/myuser/sequencefile");
SequenceFile.Reader reader = new Reader(config, Reader.file(path));
WritableComparable key = (WritableComparable) reader.getKeyClass()
.newInstance();
Writable value = (Writable) reader.getValueClass().newInstance();
while (reader.next(key, value)) {
System.out.println(key);
System.out.println(value);
System.out.println("------------------------");
}
reader.close();
Extra info, here is the sample output running against the data file generated by Nutch/injector:
------------------------
https://wiki.openoffice.org/wiki/Ru/FAQ
Version: 7
Status: 1 (db_unfetched)
Fetch time: Sun Apr 13 16:12:59 MDT 2014
Modified time: Wed Dec 31 17:00:00 MST 1969
Retries since fetch: 0
Retry interval: 2592000 seconds (30 days)
Score: 1.0
Signature: null
Metadata:
------------------------
https://www.bankhapoalim.co.il/
Version: 7
Status: 1 (db_unfetched)
Fetch time: Sun Apr 13 16:12:59 MDT 2014
Modified time: Wed Dec 31 17:00:00 MST 1969
Retries since fetch: 0
Retry interval: 2592000 seconds (30 days)
Score: 1.0
Signature: null
Metadata:
Thanks!

g++: File not found

I have been developing a program lately that compiles and runs a C++ Program from a Java program, I have gotten everything working basically (or atleast to my knowledge) but then I noticed some things being printed to the Error Stream:
cdog5000#srv3:~$ java -Xmx50m -jar main2.jar
Running Command: sudo g++ --static -o "/home/cdog5000/cody.out" "/home/cdog5000/cody.cpp"
Err: g++: "/home/cdog5000/cody.cpp": No such file or directory
Err: g++: no input files
cdog5000#srv3:~$ ls -l
total 4548
-rwxr-xr-x 1 cdog5000 cdog5000 1297588 Feb 3 23:11 a.out
-rwxr-xr-x 1 cdog5000 cdog5000 7978 Feb 2 04:39 cody
-rw-r--r-- 1 cdog5000 cdog5000 106 Feb 4 02:09 cody.cpp
-rwxr-xr-x 1 cdog5000 cdog5000 1297357 Feb 4 02:09 cody.out
-rw-r--r-- 1 root root 410433 Feb 4 02:48 log.txt
-rwxr-xr-x 1 cdog5000 cdog5000 801088 Feb 1 05:24 main.jar
-rw-r--r-- 1 cdog5000 cdog5000 804802 Feb 4 02:49 main2.jar
drwxr-xr-x 3 cdog5000 cdog5000 4096 Feb 3 23:11 sandbox
cdog5000#srv3:~$ sudo g++ --static -o "/home/cdog5000/cody.out" "/home/cdog5000/cody.cpp"
As you can see it works if I do it via the SSH but not the Java code?
The Java code:
public static Exec exec(String cmd){
Exec exec = new Exec(cmd);
try {
long current = System.currentTimeMillis();
Process proc = Runtime.getRuntime().exec(cmd);
exec.setReturnValue(proc.waitFor());
exec.setRunTime(System.currentTimeMillis() - current);
BufferedInputStream bos = new BufferedInputStream(proc.getInputStream());
byte b[] = new byte[1024];
String content = "";
while(bos.read(b) != -1) {
content += new String(b);
}
exec.setStdIn(content.split("\n"));
content = "";
bos = new BufferedInputStream(proc.getErrorStream());
while(bos.read(b) != -1) {
content += new String(b);
}
exec.setStdErr(content.split("\n"));
} catch (Exception e) {
e.printStackTrace();
}
return exec;
}
Thanks for any help and it is apprectiated!
Err: g++: "/home/cdog5000/cody.cpp": No such file or directory
Is telling you the problem.
You have one level of quotes too many, so you're looking for "/home/cdog5000/cody.cpp" rather than /home/cdog5000/cody.cpp.
The Runtime.exec documentation says:
More precisely, the command string is broken into tokens using a StringTokenizer created by the call new StringTokenizer(command) with no further modification of the character categories. The tokens produced by the tokenizer are then placed in the new string array cmdarray, in the same order.
Meaning it only splits on whitespace, it doesn't handle double quotes like the shell does.
Many languages have two functions, one called exec which runs the command verbatim, and system which passes the string to the shell, where it will split words and expand wildcards.
I can't see a system call in Java, so I think you will have to use exec(String[] cmdarray) rather than exec(String command).
GCC doesn't lie like that - it looks like the file isn't there. Are you sure that you're showing us the output from the correct directories?

Categories

Resources