How to manage Intellij IDEA configuration? - java

I've a Java backend application (Traccar). I compile and start the application selecting the following configuration:
The I click on run to execute the program, and everything works. My question is: how can I do the same from command line? All the settings in this image, how are they translatable to some commands?
If I have to do run the program from command line, how can I select the main class (org.traccar.Main), the module (-cp tracker-server.main) and so on?
Thank you everybody.

You should compile the JAR file first and then run it using something like this:
java -jar tracker-server.jar conf/traccar.xml

Related

How to edit configurations of IDE to run a java application...? (IntelliJ)

I know how to run my Java program from the command line. My path to Main.java is:
my_dir/turtlesolution
turtlesolution has the following:
Main.java
Turtle.java
Turtles.java
I opened turtlesolution as the project, using IntelliJ. I then opened (by double clicking) Main.java. I want to run this. I have to edit configurations before I run it, it seems.
So I clicked edit configurations. I clicked JAR application because this looks like the option. This is what comes up:
Working directory, I set it to point to turtlesolution. What is Path to JAR? I tried to set it to turtlesolution but it remains blank. What does Warning, jar file doesn't exist mean?
I can run it from the command line by just doing
cd turtlesolution
javac Main.java Turtle.java Turtles.java
cd ../
java turtlesolution/Main
Aapprently it's very easy to figure out. I'm in my final year of learning CS in university and apparently it's simple, but I can't figure out how to do it, and it's too simple to teach ...
If you don't have any run configuration in the project, Run button is also disabled.
If you right click in a file with main method, run configuration is created automatically and main class value if prefilled. This worked for me for more vist https://intellij-support.jetbrains.com/hc/en-us/community/posts/206811415-Problem-with-Edit-Configurations-

Launch TestNG suite from bash script

I'm having trouble using my testNG suite in the Jenkins of my company. Here is the set up :
-Jenkins is installed on a Linux machine so I have to create a .sh which launch my tests.
-I code my tests under Windows, on Eclipse in Java.
-I have to use relative path in my project.
-I use my file blex_test_v1.xml to launch my tests.
I did write a batch script, it works fine without problem :
I now try to "convert" it into a .sh so this is what I have for the moment :
The problem is that I always get this error :
"Error Could not find or load main class org.testng.TestNG"
There is about 6 or 7 posts on StackOverflow about this problem, I've read all of them, trying to change my code, rewrite it, I even uninstall all .jar files and reinstall them in my lib ... Can't see where is the problem coming from.
It can't be from the plug-in, jar files, main Class (I don't have any), my different paths or org.testng.TestNG because my .bat is working with the same meta or maybe it is different in bash script ?
For the moment I don't use Jenkins, I first try to make a runnable script and I'm reeeeally stuck here ... What am I doing wrong ?
Thanks !
PS : Here is the architecture of my project (admire my artist skills) :
EDIT: I don't use maven nor ant nor gradle, just Java in eclipse with testNG and reportNG plug-in
EDIT 2 : I used this answer to make my bash this guy says it is working fine, but it is not for me, even if I code it with ./ (still the same error as above):
java -cp ./blex_test_v1/lib/*:./blex_test_v1/bin org.testng.TestNG ./blex_test_v1/blex_test_v1.xml
EDIT 3 : I found another typo but still got the same error :
export CLASSPATH=./blex_test_v1/lib/*:./blex_test_v1/bin;
java org.testng.TestNG blex_test_v1/blex_test_v1.xml
Note : the * makes the code look like it is commented but it is not
After a couple of days I finally solved the problem by making a main class in my Java project calling the XML file, then create an executable jar of my project and in the end create a bash script calling this jar.
The code of my .sh is here (quite simple) :
java -jar Exec.jar

Error when executing class file in command prompt

I'm currently in the process of learning more about Java. I downloaded a sample program that has about 5 different .java files in the source folder.
Whenever I try to execute the class files in the command prompt using "java ClassNameHere", I get a message in the cmd prompt that says "Error: Could not find or load main class ClassNameHere".
I've tried recompiling them using the javac command and they compiles without any issues. Its just the class file i'm having trouble with.
In addition to this, I also cannot run the java files using Eclipse. Instead of getting an option to "Run as Java Application", "non applicable" appears under the "Run as" tab in Eclipse.
I've tried a number of different solutions already posted online, including another command that uses "java -cp . ClassNameHere" or something along those lines and they have not worked for me. Any help is appreciated.
Edit
Link to program from my drive since I'm not home
https://docs.google.com/file/d/0B9_pcTVZTnfEeVdzZmM0ZmFkTmc/edit?usp=docslist_api
Here is a a procedure that will get the application working in Eclipse. This procedure assumes the following:
Windows 8. I don't think Linux/Mac OS X procedure would differ greatly, but just in case...
In Eclipse:
Right click in Package Explorer, and select New --> Java Project.
In the New Java Project dialog, uncheck Use default location, and click Browse and select the directory you've extracted the zip to, or type the path in the box.
Click Finish.
From this point, you can run this is a Java Application from Eclipse.
Confirm that at least one of the classes has a main() method. That would be required for Eclipse to show "Run as Java Application".
Follow this steps:
Run Command Prompt.
Use cd C:\path\to\your\porject\java classes.
Use set path=%path%;C:\Program Files\Java\jdk1.7.0_65\bin (CHANGE THE PATH TO YOUR jdk1.x.x_xx\bin FOLDER) to tell the system where to find jdk programs.
Use javac MainClass.java to compile the project, MainClass.java si the java class where the main method is.
Use java MainClass (WITHOUT .java EXTENSION) to run the project.
After the last command your project should run correctly.
Sorry for the "use" ripetition but i'm not english.

Running java application written using Eclipse from command prompt

I have a java application that I created using Eclipse 3.7 and also run from this IDE.
Now I want to run it from command prompt. How should I go for it?
Do i have to create jar file to do this ?
And I am also setting some system properties in run configurations, so also specify how to pass them while running it frm command prompt.
There are many tutorial. here is the general process.
Compile all classes, you may use Eclipse or javac
You do not need to Jar it up. Go to your package root. And run it as
java -cp .:path/to/requires/jars:/some/more/jar FullyQualifiedMainClassNameWithoutExtension param1 param2
If you have properties to be feed into you may have that at package root and use ClassLoader#getResourceAsStream("/filename.properties")
If you look into args of your main(String[] args) you will find param1, param2 there.
Refer
http://www.cs.usfca.edu/~parrt/course/601/lectures/java.tools.html
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ClassLoader.html
Note:
If you have multiple Jars use wldcard to include your Jars. http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
the classpath delimiter is : for Unix, and ; for Windows
This tutorial is the best example of spoon feeding. But, whatever makes you go Compile and run Java program in package from command line
Switch to the "debug" perspective and run your program in Eclipse.
Write-click the process (even after it terminates) in the "debug" window and select "properties".
In the properties dialog you see the entire command line used by eclipse. You can copy and paste it in a shell to execute it.
You might want to change the command from "javaw" to "java". Up to you.

Java - Eclipse packages

I have the following package on Eclipse:
com.mortgageapp.projects.app
I'm not interested about the package format at the moment, it's just testing. But I'm wondering how to run the app from the terminal (Windows and Mac)?
It contains a Main.java file where it will begin so I have tried locating and entering the src folder. Then doing something like: javac com/mortgageapp/projects/app/Main.java (or: javac com/mortgageapp/projects/app/*.java).
Just wondering if this is current as when I then do: java com/mortgageapp/projects/app/Main I get a few errors.
Your compilation is probably okay, but to run it you need to specify the class name, not a filename:
java com.mortgageapp.projects.app.Main
That's assuming the current directory is in the classpath. If it's not, you may need:
java -cp . com.mortgageapp.projects.app.Main
I assume you are writing an RCP application.
Export the project as a RCP application (click the "export" link in your product configuration). You should get a runnable application file.
If you really want to run the application from the terminal, you need to use the main function in the EclipseStarter. But you don't want to go there unless you are doing something very special.

Categories