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.
Related
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.
In my spring Boot web app I have added the Gradle Wrapper to source control so that a user does not need gradle pre-installed to run my application.
My project file Structure is shown below - note the gradle folder with gradle-wrapper.jar , gradle-wrapper.properties and gradlew batch file are present.
However when try to run gradlew clean build in this folder I get:
gradlew:command not found
How can I solve this?
You're missing the . dot in your command. And from your screenshot, you're own a Windows machine so you should use the .bat script.
./gradlew.bat help
Is there another way to run deployed spring boot application on server than *sh script?
My idea is create .sh script which will start app (java -jar name...). This solution is simple but have one disadvantage - I have application version in the file name. I can trust that there will be only one *jar file and run it - but I am not sure that it is best solution.
What do you think?
You could use maven-assembly-plugin to bundle your application jar and sh script onto one zip file. In this case you could use maven resource filtering to put replace ${version} placeholder in your sh with exact version of your jar during maven build.
If your jar has name like this: `my-project-.jar1 then your sh script will look like this:
java -jar my-project-${version}.jar
During build maven will replace ${version} with value from pom.xml.
So after build you need to unpack zip (or tar.gz) and execute sh script.
I was trying to execute spring boot; it works fine with mvn spring-boot:run. But when i try to package it as jar (I moved dependencies to lib, and binary to bin and resources to resources folder)
command was java -cp lib/;bin/;resource/* com.sample.SampleBoot
(SampleBoot's jar is available in bin)
This starts and print the line mentioned in main, but while calling application.run(args) [application is instance of SpringApplication), it is coming back with out starting the server.
It is not throwing any error or exception as well. So it is tough to debug.
Any help or advise?
I think you should create the jar like this
mvn package spring-boot:repackage
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
Creating a simple runnable jar file won't include the libraries in pom.xml.
If you're using eclipse, run this maven command below to create a runnable jar file in Spring Boot to include all libraries:
clean package
Reference to almost same question Exporting Spring Boot application as JAR file in eclipse
I am performing checkout from SVN which contains both Java & C++ projects. After that I am trying to do headless build using following command:
D:\Path\to\eclipse>eclipsec.exe -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data "D:\path\to\checkout" -build all
After running this what I am getting is only :
Building All Projects...
Building workspace
That's it..Its just creating a .metadata folder in the given path D:\path\to\checkout and nothing else. What is expected is it should create .dll files of C++ projects, but it does nothing.
How can I achieve proper headless build & how to manage dependencies?
UPDATE
So I imported that folder into eclipse(& closed it so that I run it from command line) and ran above command, what it is doing now is building projects but gives error whenever processing a C++ file:
fatal error C1083: Cannot open include file: 'Exceptions/Exception.h': No such file or directory
Any suggestions??