How do I execute a Java app I built with Maven? - java

I created a Maven project following the quickstart template as described in the Maven doc site. I can build it. However I'm confused: I can't find any instructions for executing an application built with Maven. I did find the suggestion I type java -cp target/Mus-1.0-SNAPSHOT.jar app.App or something similar, but this fails when I added an external dependency to my Maven project.
Surely there must be some kind of Maven command for executing an App.

Related

Groovy files throwing ClassNotFoundException in Java Spring Boot application

I have updated my STS to v4 few days ago,since then I unable to run my application which has groovy files.
I have installed Groovy Development plugin and tried to build the project using the maven command "clean install".
Maven build has been successfully executed, but when I started my project it throws that the Groovy class has not found exception.
I tried cleaning the project many times, but getting the same ClassNotFoundException for the Groovy classes.
My STS v4 installation details:
Java Build path details:
Error Details, while I am running the project:
That parser class is the groovy class which throws ClassNotFoundException.
Moreover, I the project explorer some strange icon is shown next to those kind of groovy files.
I am also attaching the maven build details,
these build information shows that those groovy files are compiled successfully, but still it throws ClassNotFoundException while starting the application.
NOTE: I gave clean - build, "clean compile" and updated maven project more than 15 times. Yet no luck.
Please help me in reSolving this issue SO!
Found the answer!
Compiler mismatch is the culprit here.

Java Cucumber - Trivago Cluecumber not creating report via runnable jar

I have a Java Cucumber project which I have to run via an executable jar (java -jar) instead of maven (mvn).
I am trying to add the Trivago Cluecumber report plugin (https://github.com/trivago/cluecumber-report-plugin) into it but it only works when I call it via the maven command:
mvn cluecumber-report:reporting
When I run the project via java -jar I can see that the plugin creates the .json file but does not create the reports with the html,css,js page.
Is there a way I can fire this plugin from my java code instead of the maven plugin in the pom.xml?
Or is there a way I can hook this plugin execution after the java cucumber framework runs?
Thanks
As Cluecumber in its current form is a Maven project, it needs to be invoked via Maven. Future versions of Cluecumber may also be usable without Maven.

How to execute maven plugins from gradle without having maven and java installed

I need to execute a maven plugin on a system that does not have both maven and java installed and installing both of them on the system is not an option. While searching for the ways, I found out that by using gradle we can build executable binaries that does not even require gradle to get executed, which perfectly fits my situation :) . Is there any way to execute maven plugins by using gradle. Thanks in advance
Java is required for Maven and for Gradle too.
You can use Maven Wrapper exactly like with Gradle.
Execute this command in project directory (this creates executable script like in gradle)
mvn -N io.takari:maven:wrapper
To invoke this project without maven installed use:
./mvnw GOAL
Gradle is a build system. You can build anything with it, including native binaries.
And yes, you can call Maven Plugins from Gradle, as Maven Plugins are written in Java and Gradle is based on Groovy and thus on Java.
But both facts have nothing to do with each other.
You can of course also use Gradle (or any other build system including manually stuffing things together) to build a distributable that includes a Java runtime environment. But then Java is, as said, shipped with your result. You cannot run Java code without having Java around, besides porting the Java code to something else like C++ that compiles to a native binary.
Yes, you can also call Java code from native code if you do some glueing, but no, also this will not work without having Java around, because that's the way Java works.
Both Maven and Gradle require java to be installed. See https://docs.gradle.org/current/userguide/installation.html

GWT maven project compiles and run from maven but don't compile and run in eclipse

I have multi module maven project, that is build with gwt as a main web framework. Here is github repo.
Everythink works as it should as I supose. I haven't got anything wrong.
Unfortunatelly the problems occur when I try to import this project into eclipse (as maven project). I can not compile this project (using RMB on project in Package Explorer -> Google -> GWT Compile).
I am getting an error:
Loading inherited module 'src.main.resources.pl.derp.parent'
Loading inherited module 'pl.derp.shared'
[ERROR] Unable to find 'pl/derp/shared.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
When I tried to RMB on Project name in Package Explorer -> Run -> Run as Web application (GWT Super Dev Mode)
I've got:
Working directory does not exist: /home/danielo/eclipseGwt/gwt_2.7.0_maven_eclipse/web/src/main/webapp
I've added modules to build path.
I've followed this instruction
I think, that I've done everything to make it work, but still can make it work.
I think the problem is in packages name, and the way they are treated by maven and eclipse. They are treated in diferent ways.
Maven easily find every class (f.e.: package pl.derp.web;) needed and compile. The eclipse is trying to find them by f.e.: src.main.java.pl.derp.web but can't found it.
Really I don't know how to resolve this issue?
I am not sure witch package name patter is better (src.main.java.pl.derp.server or pl.derp.server)- for me the shorter is better.
To run this project in maven (it is well described here):
mvn clean install
mvn tomcat7:run-war-only
and in second shell:
mvn gwt:run -pl web
And in Eclipse I think I am running built in Jetty server
Please give me some help.
You apparently have a single Eclipse project, with server, shared, and web declared as source directories. When using M2Eclipse, you should have 3 projects, each with their src/{main,test}/{java,resources} declared as source directories. At a minimum, without M2Eclipse, the source directories must be the src/{main,test}/{java,resources}, whether you have 1 or 3 projects.
This is why Eclipse looks for src.main.java.pl.derp.server instead of pl.derp.server, and why GWT fails too (classpath is similarly wrong).

Trying to compile Maven with clean parameter and got exception

Trying to compile Maven with clean parameter:
C:> mvn clean
and got the exception below:
Cannot execute mojo: clean. it requires a project with an existing pom.xml, but the buid is not using one.
can anyone tell me how I can associate my existing project to maven.
Maven uses a file called pom.xml to build. It should be located in the root of your project.
Maven works on the basis that your project conforms to the Maven way of doing things and so I would recommend reading the Maven Getting Started Guide to familiarize with the standards before starting to use Maven.
I think you need to read up on a bit of documentation. Basically it is the pom.xml file it is complaining about that defines how maven should handle your project.
This explains how you can use maven to generate an example project.
This goes in more depth and also provides some links to other resources.
suppose your project is in 'C:\MyProject' where you can see a pom.xml file, open command prompt, go to C:\MyProject and type 'mvn clean' as follows:
> cd C:\MyProject
> mvn clean
The project you are compiling is not a maven project.

Categories

Resources