I am new to programming, there is a maven project with java code that does certain testing and it runs regularly through Jenkins pipeline, it runs the tests on an environment (linux machine).
Now what I am struggling and not knowing where to start is how can I test this code manually knowing that it has different Mains (i.e Main1 , Main2 , Main3) and I want to run a certain Main not all, for example only Main1 which tests specific thing.
ps: I have the code in Intellij, but I want to run it outside intellij, I want to run it on the environment I'm testing (linux maachine).
first you have to build the maven project using this command in your project directory:
mvn package
After a successful build, you will see a .jar file has created in target folder same as your package name and version.
finally you have to RUN the project.
To run the project use this command:
java -cp target/jarfileName.jar path_of_the_project_startup
Done.
First, you need to build your maven project. Navigate to the project folder (you must have the project root pom.xml there) open a terminal and to build it type:
mvn clean package
Depending on your project structure, a successful run of this command will result in several target folders at different levels for your modules and possibly .jar files inside them. Navigate into the target folder of the module in which your entry point (main) is and check jar file name. Let's call it jarname.jar for simplicity.
In case you have several entry points in the same jarname.jar, you can run them like this:
java -cp jarname.jar Main1
java -cp jarname.jar Main2
java -cp jarname.jar Main3
If you want to run from terminal and still debug from IntelliJ, run app with:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
and then create a 'Remote JVM Debug' config in IntelliJ on same port (5005), adding some break points and 'Debug'.
As an alternative, you can create Run Config 'Java Scratch' from IntelliJ to run/debug your app.
Related
I have completed my JavaFX application within gradle build system, and it is working fine in all way. Now I want to export as a .EXE file for standalone software distribution, I tried much more tricks but no gain. If some one can help me out to wrap my project in a software setup, It would be grateful.
Follow these steps to export your JavaFX project into executable Jar
Goto> Project Structure
Goto>>Artifacts
Click "+">> To add new artifact
It will shows a dropdownlist
Select>>Jar>>From module with dependencies
You will see a nested window as shown
Select Main class of your project
Check In the Option " Copy to output directory.." >>Ok
Goto>> Menu-bar>>Build>>Build Artifacts
Select>> your Project.jar>> Build
This will create executable jar file in your project source folder
Locate your jar file in path project\out\artifacts..
Now you can run this jar file simple cmd commad or with batch file
Cmd Command>> Java -jar project.jar
Using batch file>> make .bat file name it "RUN" and write these commands inside
Specify the Java Runtime path and "Javafx Sdk path" along with VM
options & Project Jar
Run your standalone application .. Enjoy ;)
Creating an installer for the desktop platforms (Windows, macOS, Linux) has become easy these days. The tool of choice is jpackage which started to be shipped with JDK 14. It can either be used on the command line on the finished project or you can use a Gradle plugin (https://github.com/beryx/badass-jlink-plugin). If your project is not modularized you could follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which also uses jpackage but together with Maven and some other tools from the JDK. The Maven part could easily be rewritten to Gradle, if needed.
Not being able to execute the default micronaut application using basic cli commands. This problem has occured on both the Maven and Gradle default projects. I don't understand why I'm having issues running the app.
The repective default project base directories contain the mvnw and gradlew files so I don't think it's a problem with maven/gradle being out of date on my computer or anything along those lines.
I've checked the class path being passed into the arguments in both the gradlew and mvnw bat and cmd files. Their respective wrapper.jar paths are being passed in as classpath arguments.
Here's some images.
Maven error message, similar error occurs when trying to run with gradle:
Base directory of maven project:
Gradle error message:
Base directory of gradle project:
Parent directory image:
UPDATE: I just tried downloading someone else's project directory from a guide on micronauts website I unzipped it and used the ./gradlew run command, the server seems to be up and running. The zip comes with initial and completed subdirectories each with their own micronaut application inside, they run too using the same gradle command.
This leads me to believe that there was something wrong with my micronaut installation. Maybe it's shipping a faulty default application (that's not configured properly)?
It looks like you don't have the wrapper support files in your project.
~ $ mn create-app somedemoapp
| Generating Java project...
| Application created at /Users/jeffbrown/somedemoapp
~ $ cd somedemoapp/
somedemoapp $ rm -rf gradle
somedemoapp $ ./gradlew run
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
(notice that I deleted the gradle/ folder before attempting to run the project)
Some people don't check in the gradle/ directory to source code control because they don't understand its purpose.
I created a new micronaut application in my C drive with a different directory, it worked. I think it has something to do with the original path variable having too many spaces and - in it. Making the classpath (in the gradlew.bat) unreachable essentially.
I have a very large maven project, and when I'm debugging, it sucks to have to rebuild the entire project just to see the changes. My current method is to compile the java file in IntelliJ, then copy the class file in my target directory, to my tomcat/webapps/project/ directory, and replace the existing class file with the intellij compiled class file. Then rebuild the war file, and replace it with the existing war file in the tomcat/webapps directory.
I want to be able to automate this process. I looked into doing it with the javac command, but I'm having problems with packages be imported from jar files in the .m2 directory, and can't figure out how to automate the classpath, depending on the specific file. I'm sure IntelliJ does this automatically, and was wondering if there's a way to run IntelliJ's compiler from the command line, or if anyone has any insight into how I can get javac to work for just the one file in my whole project scope.
Any help is appreciate, thanks!
IntelliJ delegates (by default, there are options to delegate to the Eclipse compiler or other ones) to the javac compiler.
If you do not want to import your project into IntelliJ, then you can use maven from the command line to build the project.
If you do not want to build the whole project, then you can use javac from the command line.
To generate your classpath, use :
mvn dependency:build-classpath -Dmdep.outputFile=classpath.txt
classpath.txt will contain your classpath.
From then you can do : javac -cp (contents of classpath.txt) your java file.
IntelliJ is fast even on large maven projects and it can easily compile into an exploded war your tomcat would point to. It is unclear to me on why you would not want to benefit from IntelliJ.
I have a jar file that is being created by Spring Boot. Application runs smoothly when run by command java -jar. I want to create an install anywhere launcher with this jar file.
What I have tried is to send the Spring Boot main class (PropertiesLauncher). The issue is that calling it like this won't load the nested jars inside my executable jar and also the loader.path doesn't seems to work.
Is there a way to call the executable jar like java -jar from the install anywhere launcher?
I was thinking that another option was to create an install anywhere launcher for a script file and inside have the java -jar call. So another question will be:
How do I create an install anywhere launcher for a script file?
'execute command' step will do the trick:
Use this command line:
java -jar <path.to.jar.file>
Use EXECUTE_STDOUT, EXECUTE_STDERR and EXECUTE_EXITCODE built-in variables to catch errors and parse the jar's execution result.
Important notes:
You'll have to make sure your jar includes all of the dependencies (or at least set the classpath in the command line);
To include the dependencies within your jar using eclipse you can:
Export your project as a 'runnable jar file' and select the
'Extract/Package required libraries into generated JAR' option/s
Use Maven to build the project with dependencies; the
maven-assembly-plugin is required.
The 'execute command' will work for batch/cmd/shell scripts as well, but you'll have to make sure the scripts are extracted to a local folder such as %TEMP% or /tmp before you can use them.
Goodluck
I have selenium maven project created. For running the tests I have to run one program that will create testNG.xml which contains list of test cases to be executed.
But for that I need to run one Java program which has dependencies on other Java programs.
You need to use the maven exec plugin.
Take a look at this http://www.mojohaus.org/exec-maven-plugin/usage.html
Check the dependency in pom.xml file.
Run command
mvn install
it will install all the dependency and create .class files.
To run java file
java -cp "define all the jar files path separated by ; or :" name of java file