"Please run the JVM with -XStartOnFirstThread" lwjgl IntelliJ - java

I'm setting up LWJGL with IntelliJ - everything worked fine until I had to compile the template code. I have this error:
GLFW may only be used on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. This check may be disabled with Configuration.GLFW_CHECK_THREAD0.
I went to the edit configurations menu and did this:
What I changed it to:
This changed nothing and I'm getting the exact same error. Can someone help please?

See LWJGL "API docs" for static configuration class.
org.lwjgl.system.Configuration<T>
static Configuration<java.lang.Boolean> GLFW_CHECK_THREAD0
use a java.util.Properties properties file for command-line arguments and flags to the JVM , you only need to reference the properties file on the basic startup command line.
The problem appears to be with Mac OS requiring a special restart of the JVM because the thread may not be the first JVM thread (process) the main method is executing the code on, so it requires restart with -XstartOnFirstThread
I'm not actually familiar (vague similarity to starting my apps with a .exe i compiled) but github has a standard restart .java program to model from for that situation.
Another of that type of process.

Related

Internal error in eclipse when running java program

Eclipse froze on me earlier today, so I typed "top" into the command prompt and killed it. Now when I try to run a java application, I get this error:
eclipse\plugins\org.eclipse.jdt.debug_3.7.0.v20110509
That's all that shows up under details.
None of my previously working programs run, and I have no clue what this is. I have Eclipse 1.5.0 running 1.6 and 1.7 Java, depending on what program. Thanks for any help.
It is possible that you killed part of the process but not all of it. It is possible that a java process is running with a reference to this job. I would try restarting your computer to see if it will stop whatever process is referencing that jar.
Aside from a restart, then another option would be to use (in linux) pstree, filtered for your user to see if any other jobs are referencing that jar and/or java.
EDIT:
Another path is to look at log files. On linux they are in /var/log. Here's a link in that direction: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/felog.html

java jni Exception Access Violation

My java application which uses JNI is crashing with hs_err_pid file giving the error as "Exception Access Violation". The OS is Windows VISTA.
From what I know, my native code is illegally writing to some chunk of memory that does not belong to it.
I have used valgrind on Linux on pure native code to detect such problems in the past.
But when using java, valgrind simply fails and does not work.
What (if any) method would you suggest to identify the offending piece of code?
It is not possible for me to manually dig through the native code (few million lines) to identify it.
I was finally able to resolve the issue. I thought I will post the procedure here in case someone else is in a similar situation.
Step 1:
Build the native code with proper debugging symbols. The compiler flags could be something like "-g -rdynamic -O0".
Step 2:
The following valgrind command should do the job.
valgrind --error-limit=no --trace-children=yes --smc-check=all --leak-check=full --track-origins=yes -v $JAVA -XX:UseSSE=0 -Djava.compiler=NONE $JAVA_ARGS
In the above command, $JAVA is the java executable and $JAVA_ARGS is the arguments to your java program.
Once successfully started, it will take orders of magnitude more time to complete the execution. Valgrind will print thousands of errors (most related to jvm which can be ignored). You can however identify the ones that relate to your jni code.
This general strategy should be applicable to most native memory related problems.
If you are running Java under Linux, you could use the -XX:OnError="gdb - %p" option to run gdb when the error occurs. See this example.
Under windows, you can use the -XX:+UseOSErrorReporting option to obtain a similar effect.
For debugging JNI code a method posted in this article could be useful (it's about debugging JNI using Netbeans and Visual Studio). It's simple - just start your Java program, then in Visual Studio pick Debug -> Attach to process and choose java.exe process running your program.
When you add breakpoints to your C++ code, Visual Studio will break on them. Voila :)

Running a JAVA program as a scheduled task

I am trying to run a simple JAVA program once per day on a Windows 7 machine.
My code runs fine inside NetBeans. If I do a clean and build it suggests this:
C:\Program Files\Java\jdk1.7.0/bin/java -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
This does not work from the DOS prompt of course because of the space between program and files so I do this:
C:\Program Files\Java\jdk1.7.0/bin/java -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar" -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
This works from the DOS prompt.
I now create a task in Windows Scheduler to run:
C:\Program Files\Java\jdk1.7.0/bin/java
with arguments:
-jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
When I then run it, all I see is a DOS box flashing up for a second. I expect the code to take about 30 secs to run. The code should persist data to a database and no updates happen.
The code also uses java.util.logging so I should see log entries and I don't.
I strongly suspect that I am not running the JAVA command properly or that there's a bad classpath issue that it present when running via Scheduler that isn't there when running from the DOS prompt.
Help would be appreciated. If you've seen this before and can sort it that would be great. If you can tell me how to get a meaningful error trace from Scheduler than that would also be really helpful.
Thanks!
I Think that you could create a simple batch script that will launch your program in this way :
#echo off
REM Eventually change directory to the program directory
cd C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\
REM run the program
"C:\Program Files\Java\jdk1.7.0\bin\java.exe" -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
Copy it into the notepad and save as java_script.cmd and then schedule this script instead of the program directly.
I solved it after changing all fonts' references to "SansSerif"
I was using Jasper Reports inside Java to create a PDF file. It was working fine when I double click the batch file or Scheduler with Windows Server 2003 but not working with the Scheduler of 2008.
I tried many different things nothing worked so I though Could it be that Windows Server 2008 is blocking the access?.
Now is working perfect. So, if you are having problems check the references to anything you are using.
The scheduler will run under a different user unless you specify what user to run as. If it isn't running as your user then it won't be able to write to your directories.
The real problem to the original question is a java installation issue on Microsoft systems. Java jre installs into Program Files\java. The executable (java.exe) is only installed in that java\bin directory. Running from the command line, the os looks in the proper location for the java.exe. Running from other MS tools (such as VBA Excel or in this case TaskScheduler), it does not!
You can see that TaskScheduler is looking in the wrong place by viewing the tasks history in the TaskScheduler tool. Double click on some of the history events and one will list the action and return code. The action will show that the TaskScheduler is trying to run
"C:\Windows\system32\java.EXE"
So, copy java.exe from the java\bin directory into the place where the scheduler is looking, and now it will work.
Or update your task and provide the full path to java.exe.
You can also update the environment system path to look for java in the java\bin directory, but that has to apply to all users and sometimes this is faulty as well.

Java programme works perfectly in NetBeans, but exits unexpectedly when trying to run

I've run into a weird problem today. I'll try to describe the steps I'm making as detailed as possible.
I've created a Java application in NetBeans. The application runs without exceptions when running within NetBeans by clicking Run Main Project. The total duration of a complete run is about 1min.
When building the project I see the following option in the output window of NetBeans:
To run this application from the command line without Ant, try:
java -jar "C:\java_libraries\PrxJobCommunicator\dist\PrxJobCommunicator.jar"
So i open the command prompt (Windows 7), enter this command + supply a mandatory integer argument and press enter
The application starts running, runs for a couple of seconds and exits without any message whatsoever.
the application writes to a text file at different points in the code, so I'm able to trace the output up to the point when it stops running. I've deliberately put some extra calls to the file writer method in order to find where the programme continues/exits but to no avail. Seemingly the programme simply stops running on a certain line and that's it.
I really don't know what the problem can be: the application runs fine in NetBeans and fails without any message whatsoever when starting from the command line.
Shall I check anything special in NetBeans? Do you know of any special technique to debug a jar file if it's started from the command line?
Any clues are welcome.
Thanks, Andras
I suspect that there is a difference in the classpath when the app is run from NetBeans, and when it is run from the command line.
There must be some kind of exception that is being thrown, have you got an outermost
catch (Exception ) block in the main method?
You could try to debug the application using "remote debugging", although you won't be debugging over a network, you can still use this method to catch the breakpoint started at the command line in NetBeans.
Here's an article that explains how to do remote debugging with NetBeans http://manikandanmv.wordpress.com/2009/09/24/debugging-java-applications-with-netbeans/
Netbeans by default uses your project folder as the working folder. It means when you run your program from console you have to CD C:\java_libraries\PrxJobCommunicator
then run java -jar "C:\java_libraries\PrxJobCommunicator\dist\PrxJobCommunicator.jar"
If above fails check the java version used in your command prompt. java -version
It has to be same as the one used by netbeans.
Finally the library path. Are all the dependent jars placed in the dist folder?

JVM Launched via CreateProcess() Loses Classpath Library

I launch the following command line (process) from a Windows VC++ 6 program using CreateProcess (or _spawnv()):
java -cp c:\dir\updates.jar;c:\dir\main.jar Main
and class updates in updates.jar (overiding some in main.jar) are not read or found. It is as if the updates.jar library cannot be found or read.
If I launch the same line from a shortcut, or from the command line proper, everything IS found and executes properly.
If I launch a JVM from the command line, keep it running, AND THEN launch the executable stub (above), then everything works OK also. (This makes it look like the issue is a file rights thing).
Any insight would be greatly appreciated!
--Edward
Try using Microsoft's FileMon utility to figure out what's happening. Set the include filter to "updates" to focus in on the problem.
http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx
Have you tried this on another machine? Another OS? Which JVM are you using? Have you tried different JVMs?
Can you provide us with a minimal example which demonstrates the problem?
Thanks jdigital!
I tried FileMon and it showed me what I was doing wrong. The executable calling CreateProcess() had an unclosed file handle to updates.jar from an attempt to copy the update JAR earlier. Bad code that works in the production environment, but not in the test environment.

Categories

Resources