IntelliJ IDEA Run applications - java

Excuse me, the Run applications of IntelliJ IDEA in the picture below have questions about variables.
After the Run applications are running, will they save the previously executed variables like the JShell console of IntelliJ IDEA, and they can be used in the next execution?
I want to know whether Run applications has such a function, or only JShell console can do it.

If you click on the arrow present just after Current File, you will find an option called Edit Configurations. There you can add your own variables for running your application. And yes, you can save your configuration using the Save TEST_CLASS_NAME Configuration.

Related

Why are my Java code changes not being reflected when ran from command line but working in Eclipse?

I am using a bash script to run my Java program that I made in Eclipse and the Java program is working fine when ran from Eclipse. It has my most recent changes which I can tell by some print statements that I just inserted and ran again.
However, these print statements and all my other changes are not being seen when I run my bash script, which literally just runs the program like this (using testNG):
java -cp ".\src\main\java;lib\*;" org.testng.TestNG ParallelTestXML.xml
I have already cleaned the project in Eclipse and made sure build automatically is clicked, although I think that is to fix if it isn't compiling recent changes within Eclipse. So I have no idea what else it could be.
Because .\src\main\java doesn't do anything useful.
Eclipse has this concept called 'builders' and 'project kinds', and depending on how you've set up your java project, eclipse's build-on-save architecture works differently.
Assuming you just went: "File > New Project > Java Project", and picked all the default options, the way eclipse is set up is that you have a src dir (the fact that you write src/main/java belies that you didn't do this, but I'll continue for the sake of example), and when you save any java file in eclipse, eclipse will immediately update a built view of this, and it will be in a dir hanging off of the project root called bin.
That's where the class files live, so if you want to run off of those on the command line, the right move is:
java -cp ".\bin;lib\*;" org.testng.TestNG ParallelTestXML.xml
Adding the src dir is completely pointless, unless the class files live right next to the source files, in which case calling that dir src is obviously very silly (as a general rule in programming, picking a name that clearly lies, is a very bad idea, for obvious reasons).
If you have some other project setup, for example, you've set it up as a maven project or a gradle project, well, it depends on how you configured eclipse whether eclipse is trying to 'match' the builds, or is triggering a full maven build every time you save, or if you're supposed to invoke maven manually. Most likely the latter. Let maven do the building, and maven will then build your stuff someplace. Generally, {projroot}\target\classes, but to 'run' your app if your app is built with maven, don't invoke java. invoke mvn, asking it to test your stuff. That way mvn will take care of your deps and the like.

Making a Java Console Application

I wonder if it's possible to create a java console application where someone can download my packages, run and use that application in Command Line/Terminal or with some other console application.
I am very well versed in Java & the reason I'm asking is, I have a chess game which I have made to be run in command line, but how do I get it to run like an application?
To wit: On a mac, just like one who has Home brew can download formulas and use their specific commands to begin and run them, how can I do this for an already made application. Do I need a config file? Or is it just good to go as it is.
So I don't want someone to download the package and have to use the "javac/java" command to compile and run it, but can just say something like "run chess" and it does so. Any help or resources would be appreciated
You need to convert your .jar to .exe
There is a lot of software doing this, for example JSmooth.
You need to choose the starting application class and then run it.

Terminal edited files cannot be run by eclipse

I am using eclipse on linux, and I have mostly been writing java files by editing the raw text file. My reasoning behind this is that I am in a comp sci course, and we have to write code by hand, so this will prepare me for writing code unaided. However, my actual problem arose when I tried to edit a file I had created using eclipse 3.8.1. When I tried to open the folder, which has the same structure as files created by eclipse if it matters, it opens, but I cannot run it. When I click run, it asks what to run it as, and the only 2 options are Ant Builds. I don't know what this means, but I am not able to run the file either way. Any help is appreciated, and if it is important, I am using java 8.

Running multiple files in Eclipse

I am doing a distributed systems project & I want to run multiple servers (of a same file ) by eclipse at the same time on my local system,
Is it possible to do that ? generally, is it possible to run multiple files (e.g. a client and a server) on one eclipse ?
You cannot directly launch multiple launch configuration at once: there is an old bug still pending, which involves the "launch group" option (present in the "C/C++ Development Tools" plugin, but usable for other non-C++ project.
But you can run multiple launch configuration one after the other.
As illustrated in "Run two Java programs from Eclipse at once?", you will have multiple console.
And you can script that launch sequence with escript.
If by file you mean program, yes.
Yes.
You can start multiple servers one by one, and then swith to your program want to run. and run again directly. Or you can set up many run configurations manuly and then run them one by one. Any unclear pls point out.

Can I run the jetty-maven-plugin from within Eclipse?

We're debugging java webapps, and would like to use the jetty-maven-plugin to launch a Jetty server. All of the documentation I have seen suggests that you should do it from the command line, which makes debugging and setting breakpoints in Eclipse difficult. Plus I'd like to see the output in the console window and be able to stop the process with red button. And do profiling as well.
Anyone know how to do this?
Yes, if you have m2eclipse installed then just enter in "jetty:run" as the goal you want to run.
You can however connect Eclipse's (or any IDE's) debugger to a running Jetty instance by launching the jetty plugin with the JPDA flags, without having to execute from within Eclipse.

Categories