UnsatisfiedLinkError no jogl in java.library.path - java

I'm trying to build a jogl app. I downloaded the jars and the native dll files. I have included them in my buildpath but when I run my code I get a the error from the title
Here is my vm file:
-server
-Xms128m
-Xmx512m
-XX:MaxPermSize=250m
-XX:ReservedCodeCacheSize=64m
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+UseCodeCacheFlushing
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-Djava.library.path="C:\Users\Vlad\Documents\dev\jogamp-all-platforms\lib\windows-amd64"
Here is that folder:
Here are the jars that I have in my build path:
And finally if there is any need for the actual code here it is:
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.swing.*;
/**
* on 20/02/14.
*/
public class Demo extends JFrame {
static Demo app = new Demo();
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
app.setVisible(true);
}
});
}
public Demo(){
super("This is my first jogl app");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GLCapabilities caps = new GLCapabilities();
GLCanvas canvas = new GLCanvas(caps);
canvas.addGLEventListener(new MyGLListener());
getContentPane().add(canvas);
}
}
EDIT
I have changed the libraries to match the new ones:
As you can see I have the natives and the jogl-all.jar and even the gluegen-rt.jar library.
The error that I get now is a compiler error:
This is the piece of code that's causing it:
GLCanvas canvas = new GLCanvas(new GLCapabilities());
It says that GLCapabilites (GLProfiles) in GLCapabilties cannot be applied to ();

You may also need to include gluegen-rt.jar in your build path. You should be able to obtain this from the same place where you found jogl-all.jar (JOGL 2).
Regarding your edit, for simplicity, you can use:
GLCanvas canvas = new GLCanvas(new GLCapabilities(null));
This will allow you to use the default GLProfile.

Your source code uses JOGL 1 whereas you try to use JOGL 2 JARs with it. Rather look at my simple example on Wikipedia. You can find the instructions to install JOGL in our Wiki here.

Related

JCEF (Java Chromium Embedded Framework) Browser does not load content; only blank screen on Eclipse

I have been trying to get the Java version of Chromium Embedded Framework (JCEF) to work on Eclipse for some time. I am able to verify that the library files are working correctly, since if I run the included sample class files on the VM, the program runs and some webpage is displayed. However, if I run the program from Eclipse, the program will always display a blank window. I am able to verify that the library binary jcef_helper.exe is successfully run, but not matter how I link the .jar files and other library files, the webpage will not generate and there will always be a blank screen. I cannot pinpoint the issue here. I tried specifying path, adding the JCEF library path of my OS environment variables PATH field to no avail. I have followed the documentation, even sample files behave the same way when I have anything to do with compilation/ run. One note of interest, my Eclipse console will display this during run:
initialize on Thread[AWT-EventQueue-0,6,main]
Perhaps there is a thread issue?
Code in question:
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import org.cef.CefApp;
import org.cef.CefApp.CefAppState;
import org.cef.CefClient;
import org.cef.CefSettings;
import org.cef.browser.CefBrowser;
import org.cef.handler.CefAppHandlerAdapter;
public class WebV
{
public static void main(String args[])
{
Dimension dispDimension = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)Math.round(dispDimension.getWidth() / 2);
int height = (int)Math.round(dispDimension.getHeight() / 2);
CefApp.addAppHandler(new CefAppHandlerAdapter(null)
{
#Override
public void stateHasChanged(CefAppState state)
{
if(state == CefAppState.TERMINATED)
{
System.exit(0);
}
}
});
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = false;
CefApp cefApp = CefApp.getInstance(settings);
CefClient client = cefApp.createClient();
CefBrowser browser = client.createBrowser("http://www.google.com", false, false);
Component browserComponent = browser.getUIComponent();
JFrame frame = new JFrame();
frame.setTitle("WebV");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setResizable(true);
frame.setLocationRelativeTo(null);
frame.add(browserComponent);
frame.setVisible(true);
}
}
Tested with both Java 17 and Java 8.
Run on Eclipse, with VM args:
-Djava.library.path=./bin/lib/win64
Any inupt would be greatly appreicated.
This answer was kindly provided by 'Yanovsky' at the JCEF forums.
The simple example provided by the JCEF package is incomplete.
We need to add a CefMessageRouter instance to our browser client. This is demonstrated in the detailed examples, but not the simple one. This code should be added before we create our CefBrowser instance and after we have created a CefClient object:
CefMessageRouter msgRouter = CefMessageRouter.create();
msgRouter.addHandler(new MessageRouterHandler(), true);
msgRouter.addHandler(new MessageRouterHandlerEx(client), false);
client.addMessageRouter(msgRouter);
For reference, this is my post in the JCEF forum:
https://magpcss.org/ceforum/viewtopic.php?f=17&t=18834&sid=45381db639d1621f2f8b38b4d8848800
I just copied and pasted your code in eclipse and added the jars and ran the code and voila, google.com opened without any issues.
I didnt have to add any more new lines as suggested by mindoverflow.
The webpage was visible in the window after a few secs and not immediately.
Here's what popped up after running the code.
And in the eclipse console, I see this
initialize on Thread[AWT-EventQueue-0,6,main] with library path C:\path\to\dlls

Instantiating a Java AWT object causes empty application to open on macOS

When I instantiate an object from java.awt, the program causes a new macOS application named "Java", with no windows, to open.
How can I prevent this from happening?
Here is a minimal example:
import java.awt.Rectangle;
public class Main {
public static void main(String[] args) {
Rectangle rect = new Rectangle();
}
}
After compiling and running it in the most canonical way (javac Main.java; java Main), the following icon appears in the Dock: screenshot
I've traced the code, and the offending method is Toolkit.loadLibraries() (JDK 1.8.0_172-b11).
I found the solution based on #MadProgrammer's comment.
The answer is to set AWT to headless mode.
When executing the program:
$ java -Djava.awt.headless=true Main
Or programatically:
System.setProperty("java.awt.headless", "true");

Using External .jars compile time vs run time

I'm trying to break into java and game programming using opengl. I built jogl and gluegen using ant and all junit tests ran successfully. However, when I attempt to run a simple OpenGL test program it gives me a "Could not find or load main class..." error. When compiling the program I enter:
javac -cp etc...\jogl-all.jar;etc...\gluegen-rt.jar filename.java
into the command line and I receive no compile-time errors. Then I attempt to run the program using:
java -cp etc...\jogl-all.jar;etc...\gluegen-rt.jar filename
and it tells me it cannot locate the main class.
Is this an error caused by using the external .jars? Or am I not using the -cp function properly? Any help would be appreciated!
The following is the code I'm trying to run:
import com.jogamp.opengl.*;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.common.type.*;
public class SimpleScene {
public static void main(String args[]) {
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
GLWindow window = GLWindow.create(caps);
window.setSize(300, 300);
window.setVisible(true);
window.setTitle("NEWT Window Test");
window.addWindowListener(new WindowAdapter() {
public void windowDestroyNotify(WindowEvent arg0) {
System.exit(0);
};
});
}
}

Failed to read environment variable

i'm installing eclipse plugin, ArcGis Runtime SDK for java, but when i create a simple map application and then i run it, it wasn't right
my code :
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.esri.runtime.ArcGISRuntime;
import com.esri.map.JMap;
import com.esri.map.MapOptions;
import com.esri.map.MapOptions.MapType;
public class coba2class {
private JFrame window;
private JMap map;
public coba2class() {
window = new JFrame();
window.setSize(800, 600);
window.setLocationRelativeTo(null); // center on screen
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setLayout(new BorderLayout(0, 0));
// dispose map just before application window is closed.
window.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent windowEvent) {
super.windowClosing(windowEvent);
map.dispose();
}
});
// Before this application is deployed you must register the application on
// http://developers.arcgis.com and set the Client ID in the application as shown
// below. This will license your application to use Basic level functionality.
//
// If you need to license your application for Standard level functionality, please
// refer to the documentation on http://developers.arcgis.com
//
//ArcGISRuntime.setClientID("your Client ID");
// Using MapOptions allows for a common online basemap to be chosen
MapOptions mapOptions = new MapOptions(MapType.TOPO);
map = new JMap(mapOptions);
// If you don't use MapOptions, use the empty JMap constructor and add a tiled layer
//map = new JMap();
//ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
// "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
//map.getLayers().add(tiledLayer);
// Add the JMap to the JFrame's content pane
window.getContentPane().add(map);
}
/**
* Starting point of this application.
* #param args
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
try {
coba2class application = new coba2class();
application.window.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
and after i run this, i got this warning.
Java version : 1.8.0_25 (Oracle Corporation) amd64 Rendering engine :
DirectX java.lang.RuntimeException: Unable to find runtime
installation. Searched following places: F:\coba2 Failed to read
environment variable ARCGISRUNTIMESDKJAVA_10_2_4
com.esri.runtime.ArcGISRuntime.getInstallDirectory(Unknown Source)
com.esri.runtime.ArcGISRuntime.a(Unknown Source)
com.esri.runtime.ArcGISRuntime.getClientLibPath(Unknown Source)
This happens when your app can't find an ArcGIS Runtime deployment.
If you're running on a machine WITH the ArcGIS Runtime SDK for Java installed, set the value of environment variable ARCGISRUNTIMESDKJAVA_10_2_4 to the directory where arcgisruntime10.2.4 is located. The default value is C:\Program Files (x86)\ArcGIS SDKs\java10.2.4, though the SDK installer should have set this environment variable for you.
If you're running on a machine WITHOUT the ArcGIS Runtime SDK for Java installed, create a Runtime deployment and place it in the working directory for your app (F:\coba2 in your case). This is how you deploy ArcGIS Runtime to end-user machines.
Alternatively, you can set the directory containing the ArcGIS Runtime deployment programmatically using ArcGISRuntime.setInstallDirectory(String), but I don't recommend it because then your app will require that the Runtime deployment be located in the same directory on every machine.

Java helloworldswt tutorial doesn't work

I am new to Java/SWT/Eclipse and trying to learn SWT and I am having difficulties to get the following code working.Can someone help ?
Code:
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class HelloHelloSWT {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello world!");
shell.open();
while(!shell.isDisposed()){
display.sleep();
}
display.dispose();
shell.close();
}}
Well I tried running it the same way as the first tutorial, but this error popped up:
Error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-win32-4333 in java.library.path
no swt-win32 in java.library.path
Can't load library: C:\Users\sdp0121\.swt\lib\win32\x86\swt-win32-4333.dll
Can't load library: C:\Users\sdp0121\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:331)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
at HelloHelloSWT.main(HelloHelloSWT.java:8)
Go back to the step of the tutorial titled "Configure the Java project". Then go into the project Properties and select Java Build Path then expand the reference to the SWT project (small triangle before the project name). If it says "None", click Edit and find the SWT project in my workspace.
Hope this helps.

Categories

Resources