Eclipse Command Line Java - java

I would like to see the command that Eclipse is running when I hit run for a Java program. I've looked around the Eclipse preferences for Run/Debug (and console) and the Run Configurations, but to no avail. How can I see the line that Eclipse is using to launch?
In JBuilder, it was the first line in the output.
Edit: I'm not asking whether it uses javac to compile and then java to run. I want to see the line that starts with java and has all the flags, etc. I'm not asking "what does Eclipse run?" since I already know that. I want to see it in a specific case in a specific project.

Set up a launch configuration, then run or debug it.
Go to the "Debug" window of the Debug perspective, the one that shows all the processes and threads.
Right click on the java.exe or javaw.exe item in the tree (its at the bottom under all of the threadgroups and threads), and choose "Properties" on that guy.
You should get a window that contains 2 sections, the left being a list of items, including "process information" and "vm capabilities"
The process information section has 3 sections, showing the time it launched the session, the path to the exe, and the full command line that eclipse used to start the VM. The command line will include everything, including library paths, classpaths, the debug info it passes to the VM, any custom args you pass, etc.
I think that's what you're looking for.

On Unix systems you can see the command line with
ps -e x | grep java
For example (line wrapped for readability):
24925 pts/6 Sl 0:16
/usr/lib/jvm/java-6-openjdk/bin/java
-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:53880
-Dfile.encoding=UTF-8
-Xbootclasspath:/usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar
:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar
:/usr/share/java/gnome-java-bridge.jar
-classpath /home/hendrik/workspace/webflag/WEB-INF/classes
:/home/hendrik/workspace/webflag/WEB-INF/lib/log4j.jar
:/home/hendrik/workspace/webflag/WEB-INF/lib/junit.jar
nhb.webflag.importtools.tools.ImportArmoryCharacter
-agentlib specifies the debugging connection, -Xbootclasspath is based on the JDK configuration, -classpath based on the build path settings of the project

If it can find any class with the main method, it runs that using "java com.example.Main" where Main is the class with main method.
If you have many classes with main method, then eclipse gives you an option to choose one.

Related

Downloaded Eclipse IDE recently and am facing this error message every time I try to open it. What is the cause behind it and how can I solve? [duplicate]

Sometimes I have to deal with an improperly configured Eclipse installation and when I try to run it only the dialog "Java was started but returned exit code shows up without giving me any useful information to trace the actual reason Java failed to start.
What is the best approach to debug this kind of problem?
There are several command-line options that can help with troubleshooting. I'd start with -debug -consoleLog and see if that produces useful output.
You can run eclipse with the verbose attribute from command line
eclipse -verbose
Read more about debugging eclipse and plugins here http://exploreeclipse.blogspot.nl/2014/01/enable-eclipse-verbose-for-trouble.html?m=1
By default, eclipse launches with javaw.exe process, since it's a window thread so you will not be able to see any verbose messages.
Step 1: Add below VM parameter in eclipse.ini file. By default, eclipse will have javaw.exe, modify it to java.exe
-vm
C:/KK/jdk1.6.0_32/bin/java.exe
Step 2: Pass verbose parameter during the eclipse launch.
eclipse -verbose

How to "time" a Java Program in Intellij

I am currently using time command from the terminal to check how much time my java program took, using the following command.
time java -Djava.util.concurrent.ForkJoinPool.common.parallelism=40 TestingNumberOfThreads
// Result
real 0m4.356s
user 0m46.273s
sys 0m0.702s
Is there a way I can achieve the same from IntelliJ?
You’d need a profiler. I believe the plugin VisualVM Profiler for IntelliJ might be what you’re looking for.
Here’s the link to it: https://plugins.jetbrains.com/plugin/3749-visualvm-profiler/
To open the terminal window in Intellij,
From the main menu, select View | Tool Windows | Terminal or press Alt+F12.
See https://www.jetbrains.com/help/idea/terminal-emulator.html#open-terminal
Once you opened the terminal window in the IDE, you can run any command you like, including, but not limited to
time java -Djava.util.concurrent.ForkJoinPool.common.parallelism=40 TestingNumberOfThreads
You can even separate this terminal command into its own file, named to something like mycommand.sh. And, assuming that this file contains the command above, you can simplify your command to
sh <yourpath>/mycommand.sh

How to run java class in Eclipse Che

I have just started using Eclipse che and started up a project. I have no Main class and I want to start running the project from a class called TBB_SQLBuilder.java within a package called Console.
I simply cannot figure out how to run it. I have a screenshot here:
It turns out it isnt as straight forward as desktop Eclipse.
Create a bin folder
Go to the command tab on the left hand side of the IDS (I didn't have Run>Edit Commands tab for reasons I'm yet to understand)
Add a new command
I had to add
cd ${current.project.path}
javac -classpath ${project.java.classpath} -sourcepath ${project.java.sourcepath} -d ${project.java.output.dir} src/Console/TBB_SQLBuilder.java
java -classpath ${project.java.classpath}${project.java.output.dir} TBB_SQLBuilder
to get it to run.
I note the question has been downvoted. I suppose some thought this might be straightforwrd but it is worth noting that this is very different to the desktop IDE which provides a UI to create the run configuration. Che seems to rely on creating commands from a command line box in the command interface.

Output of application based on Eclipse on Windows command line only visible when piped (not directly in cmd)

We have a Java application based on Eclipse (main class implements IApplication) that is started from the Windows command line. Its output on System.out is not visible/printed into the command window from which it is started. Nevertheless, when piping the output to more, the output is fine. How come?
For example, consider helloworld.exe. When running C:\>helloworld.exe in a command window, the application simply returns. But when running C:\>helloworld.exe | more, the screen shows
C:>helloworld.exe | more
hello world
C:>
On linux, the output is fine. How to see the output on Windows, too?
Some reqested information:
The application is quite large. And I probably cannot cut it down. The output are simple calls to System.out.prinln("xxx");
Java version 1.8.0_60, Eclipse 3.6.2
Using >std.txt 2>err.txt shows that output is indeed on stdout.
Line endings are CR/LF
the .ini file is as follows
--launcher.suppressErrors
-vmargs
-Xms256m
-Xmx4096m
-Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
-Djava.library.path=plugins
Maybe this issue is related?
If your application is somehow started via eclipse.exe (has no console attached to it) change the call to use the eclipsec.exe (has a console attached to it, note the c in the application name).
You can launch Eclipse RCP based applications using equinox launcher as shown below:
java -jar plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
Of course you have to find the correct version of equinox launcher you are using in your RCP Application.
This way you would see the console logs.
You can read more about it here: http://wiki.eclipse.org/index.php/Starting_Eclipse_Commandline_With_Equinox_Launcher
EDIT: The reason you don't get console logs when eclipse.exe based launcher is used is because eclipse.exe on Windows spawns a separate process which brings up another command prompt window.
You'd better use a framework to handle your logs like logback
This is much more portable and maintainable.
In your example it seems that you have created an exe from your java code. My guess is that the packager you used to create the exe made some changes to the output target because it is a wrapper for your java program.
Try creating a jar instead and try executing it by java -jar helloworld.jar.
Is the string going to stderr in place of stdout? (or the other way around depending on your expected behaviour).
https://support.microsoft.com/en-us/kb/110930

Using Bumblee (Graphics Drivers) with Eclipse IDE [duplicate]

Does anyone know how to make eclipse or netbeans use the graphics card in optimus laptops by invoking optirun (bumblebee) inside the IDE so that one can just use the run button in the IDE to run the program in a graphics card within the IDE.
In simplest form I just want the IDE to do the equivalent of optirun ./javaproject
The way I did this in Eclipse was to first start the Java debugger jdwp and listen to a port. Then start the JVM with optirun java ... and use jdwp to connect to this port. Both tasks can be started at the same time in Eclipse by creating a Launch Group in the debug configuration settings (Run -> Debug Configurations). In detail:
Create a Remote Java Application debug configuration with "Standard (Socket Listen)" Connection Type and some arbitrary port, e.g. 56789. This attaches the Java debugger jdwp on port 56789 to a virtual machine which accepts debug connections at this port.
Now we need to start a JVM with optirun. This can be done with a External Tool Configuration (Run -> External Tools -> External Tool Configurations). Create a new Program configuration in the left side of the External Tools Configurations window. You could directly start optirun java <additional arguments> by filling in the required fields. However, I have decided to use a shell script which is reusable by different projects (As can be seen below, there is one part missing to make it entirely reusable. I'm glad for any help from more experienced Eclipse users...). Hence, the Location field points to this shell script. The script itself accepts three arguments: the classpath for the project, the name of the Java executable, and the port number. These arguments can be passed to the script in the Arguments field of the Main tab, e.g.
${project_classpath:${selected_resource_name}}
ExecName
56789
The shell script looks like this, assuming optirun is in your PATH:
#!/bin/sh
CLASS_PATH=${1}
JAVA_EXECUTABLE=${2}
PORT=${3}
# TODO: fix this java library path: pass it as an argument as well. Is there an Eclipse variable which stores this?
JAVA_LIBRARY_PATH=/usr/local/share/OpenCV/java
#------------------------------------------------------------------------------
optirun ${JAVA_BIN} -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:${PORT} -Djava.library.path=${JAVA_LIBRARY_PATH} -Dfile.encoding=UTF-8 -classpath ${CLASS_PATH} ${JAVA_EXECUTABLE}
#------------------------------------------------------------------------------
Finally, the two pieces are brought together in a Launch Group in the Debug Configurations window (Run -> Debug Configurations). Create a new Launch Group and add the two previously generated Debug configurations by clicking on Add in the Launches tab and by selecting the appropriate configurations.
Note that due to the classpath variable in step 2 (i.e. ${project_classpath:${selected_resource_name}}), the appropriate package needs to be selected in the Package Explorer before clicking on the run debug configuration button (make sure that the Launch Group is selected).
This solution works perfectly for me: I can debug Java code inside Eclipse which calls native code involving CUDA optimizations and Bumblebee only activates the discrete graphics card when necessary.
Just use optirun to start the IDE. For example, optirun eclipse or optirun netbeans
I build the project in Netbeans (F11) and run the following in a terminal:
optirun java -jar path/to/javaproject/dist/javaproject.jar
Mind that if you have any java parameters in your project, you need to add it manually. My workflow is like this:
Locate the Java options from the project, open Project -> Properties, Run. At VM Options I see -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux. I also have some parameters that I want to pass to main(String[]). With this information, I open a terminal and run:
cd path/to/javaproject
optirun java -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux \
-jar dist/javaproject.jar some paremeters
Another hint, if you have to open and close the program frequently, run optirun bash in a different tab so that preparing the use of the graphics card becomes faster. Alternatively, you can run optirun netbeans, but that means that the nvidia card will always be on even if you are programming which increases power use and increase the heat.
Important: if you are using a 32-bit JVM or Java libraries on a 64-bit machine, you also need to install the 32-bit drivers and libraries. For Ubuntu, the nvidia package already contains 32-bit drivers, see this answer. For other distros, you likely need to install lib32-* packages for Mesa, VirtualGL and nvidia-utils.
You can also rename java to java_real and use this portion of code as your java command :
#!/bin/bash
path=$(dirname $(readlink -f $0))
args=""
runner="$path/java_real"
for var in "$#"
do
if [ "$var" = "-3d" ]; then
runner="primusrun $runner"
else
args="$args $var"
fi
done
$runner $args
NOTE : I had to do this in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin, not in /usr/bin to make it work with Eclipse.
In Eclipse, just add "-3d" in your program arguments and you're good to go !

Categories

Resources