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.
Related
Let me summarize the problem:
An exercise asked me to launch a java application using the Windows 10 Command Line.
It taught me on a video how to add the IntelliJ path to the Environment Variables, so that, whenever I typed java Main I would get my Main.java/class application back.
The first problem that I had stumbled upon was that, instead of using java Main, I'd have to type java Main.java. I thought that it was due to a recent build for the JDK (v14.02), so I let that one pass.
The second problem that I had encountered was that, when the exercise asked me to launch an application using the package directories, the command line would return the following error: Error: Could not find or load main class com.pluralsight.organized.Main. Caused by: java.lang.ClassNotFoundException: com.pluralsight.organized.Main.
Revert whatever damage you've done to the system.
Install the Oracle JDK.
Put the Oracle JDK bin folder on your PATH variable.
Compile your code using javac Main.java
Run your compiled code using java Main
for the ones in the packages, you need to be at the package root, or have a class path to it. For example, let's consider a class com.example.Main
The folder structure should be:
D:/SomePath/com/example/Main.class
Then you need to be at D:/SomePath/ to execute java com.example.Main.
Alternatively, you could be anywhere else and execute java -cp D:/SomePath com.example.Main.
I have a Main.java file and I want to run the program passing it test.txt
I know in command line I can write javac Main.java
After compiling I can write java Main test.txt and this will accomplish running the file and passing test.txt
If I wanted instead to be able to just write main test.txt and have that trigger my Main.class file to run is that possible and if so how?
(Edit: Based on your comment, let me expand to add a couple more situations)
If your goal is to have someone else run your program who does not have Java installed, and you do not wish to have them install a Java runtime environment before running your app, what you need is a program that converts the .class or .jar files into a native executable for the platform you are using. How to do this has been covered in other questions, eg: Compiling a java program into an executable . Essentially, you use a program like JCG (GNU Compiler for Java) or Excelsior JET (a commercial product) to expand the byte code into full native code with a mini-JRE built in.
If your goal is to save typing, there are a number of strategies. Others have suggested alias commands, which work well on linux.
A slightly more portable option that you could ship with your program would be a shell script. Granted, shell scripts only run on linux or other OS's with shell script interpreters installed.
Here is an example shell script. You paste this into a text editor and save it as main with no extensio. The $1 passes the parameter argument fyi.
#!/bin/sh
java Main $1
presuming you name your shell script just "main" with no extension, you could call main test.txt to execute your program now.
If you are on Windows, you might want to create a windows shortcut, and point the shortcut to "java Main test.text", using the full paths if necessary (if the paths are not already set). Of course, this does not make the parameter easy to change every time you run it, you would have to edit the shortcut.
add an alias
e.g. under a mac edit your .bash_profile with the following line
alias main='java main'
don't forget to open a new console to see your alias working
Depends on your operating system. On Linux with the bash shell, for instance, you can set up an alias to expand your main into java -cp myjar.jar main.
Linux can also be configured to 'understand' Java class flies as a binary format directly see here (linux kernel documentation).
If you're on windows, you'll have to wait for answer from someone with more knowledge about that than I.
Good luck!
I've created a stand alone a java application in Ubuntu 10.04 using Netbeans 6.9. I'm not able to use use the getenv() command in Netbeans, though if i create a separate java file in gedit and compile it in the terminal then it gives the desired output.
System.out.println(System.getenv("TRGRAPH"));
The above code when executed through the terminal gives the desired output but the same code if i try to run in Netbeans then it returns a null string.
Can anyone tell me how to get the output using netbeans??
You need to launch Netbeans from the same terminal after you have set and exported TRGRAPH.
Example, in a terminal:
$ export TRGRAPH=foo
$ netbeans&
I use Eclipse, not NetBeans, but I bet they are similar. Look for a dialog that controls how your program gets launched. This dialog probably has a place where you can specify environment variables that should be set when your app is launched.
The other alternative is to set the environment variable before you launch Netbeans.
It means that TRGRAPH is not defined in the process. The environment gets inherited from the environment of Netbeans. Make sure, that Netbeans gets the variable, e.g., by starting it from a command line or by invoking it using a shell script sourcing your .bashrc (or wherever you define TRGRAPH).
Alternatively, you can start an external Java process using the ProcessBuilder and pass it any environment you like. Quite complicated, but very flexible.
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.
I just installed Java Developer on Windows Vista. The installation process looked OK and it was successfuly finished. However, I do not know how I cun run this program? Nothing new on the desctop appeared?
First of all it is important to note that the Java Development Kit (JDK) is not a GUI tools such as Visual Studio. It consists mainly of pure command-line tools used to compile, run and debug Java code.
There are IDEs (Integrated Development Environment) which provide the entire Editor/Compiler/Build-System integrated in one big setup, but in my opinion the very first steps should be done with the pure JDK.
Start with this intial Java tutorial.
Generally The Really Big Index should keep you occupied for quite some time.
Fetch yourself a development environment like Eclipse: http://www.eclipse.org/ and start playing around.
The JDK is just that: a software development kit, sitting around in a directory specified by you and waiting for you to invoke its command line tools ...
If by "Java Developer" you mean the Java Development Kit (JDK), then you "run" it via the command line - use javac to compile and java or javaw to run the compiled classes.
If you mean you installed the JDK—the Java development kit—then this is just the Java compiler and the sources of the class library (roughly). You can then go ahead, create Java programs in any text editor and compile them.
But you probably want an IDE, such as Eclipse.
Go to Command Prompt. In the command prompt go to the directory where the Java program is located. In the command line type "java name_of_the_program.java". It will generate name_of_the_program.class. After that you can type (in the command line) "javac name_of_the_program" and the program will be executed.
It is how it should be in theory. But in practice it will not work. To make it work you have to find your java-directory (a directory where "javac.exe" is located). In my case it was "C:\Program Files\Java\jdk1.6.0_18". Then you have to create 4 new environment variables (classpath, include, lib, path) and set them to be equal to the name of the above mentioned directory. After that you need to restart your computer and after that will be able to compile your progam (by typing "javac name_of_the_program.java").
But of couse it is not the end of the story. If you type "java name_of_the_program" the program will not be executed. Java will write you that it is cannot find the main class. How to solve this problem I do not know yet.