I build library which use spring-boot-autoconfigure to configure spring context. I build project by maven config in Intelij and it work perfect, but when i run mvn clean install in terminal maven throw errors that it is impossible to find any method, classes etc. Project is library so build configuration cannot include any main path.
This is my maven config
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
The command which intellij execute in maven clean install config look like this
<java-path> -Dmaven.multiModuleProjectDirectory=<project-root-dir-path> -Dmaven.home=<intellij-maven-path> -Dclassworlds.conf=/.../JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/plugins/maven/lib/maven3/bin/m2.conf -javaagent:/.../JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/lib/idea_rt.jar=37847:/.../JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/bin -Dfile.encoding=UTF-8 -classpath /.../JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3.4 clean install
The dots in paths are my system path to JetBrains directory.
Can anyone give me tip to configure this maven project to build jar by clean install. Remember that there is no main method because it is only library project.
Thanks to Ajay Kumar adding this dependencies repair the problem
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13-ea+11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13-ea+11</version>
</dependency>
Related
I have a problem with a Spring boot project, it has another spring boot project as a dependency in its pom.xml.
I can run it properly using eclipse, but an error shows up when I try to run it with terminal using the command mvn spring-boot:run.
[ERROR] Failed to execute goal on project platform-service: Could not resolve dependencies for project com.test.platform:platform-service:jar:0.0.1-SNAPSHOT: Could not find artifact com.test:student-service:jar:exec:0.0.1-SNAPSHOT
This is how I added the dependency in pom.xml :
<dependency>
<groupId>com.test</groupId>
<artifactId>student-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I have tried different solutions like mvn package spring-boot:repackage but it didn't work.
Thank you so much.
Add this plugin after dependencies in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Save this and run again.
I am new to using Maven and Eclipse, I am following this link.
Below is the pom.xml I have in my workspace:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.HelloWorld</groupId>
<artifactId>SpringHelloWorld</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SpringHelloWorld Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jdk.version>1.6</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SpringHelloWorld</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
For adding the required jars, I run the below command from command prompt:
mvn eclipse:eclipse -Dwtpversion=2.0
I got the "BUILD SUCCESS" message in my console. But when I refresh the project in Eclipse IDE, I can see all the libraries are missing and the path for those jars does not exists.
e.g.
Description Resource Path Location Type
Project 'SpringHelloWorld' is missing required library: 'C:\Users\username\.m2\repository\org\springframework\spring-aop\3.0.5.RELEASE\spring-aop-3.0.5.RELEASE.jar' SpringHelloWorld Build path Build Path Problem
For this error, when I check manually, I can't see any folder named springframework inside the org folder, hence the jar is missing and the error is displaye din Eclipse IDE.
I tried running the command mvn eclipse:eclipse -Dwtpversion=2.0 multiple times but of no use.
Please advice how to resolve this.
EDIT
Below is the snapshot of the Eclipse Installations:
EDIT 2
I am not getting the Maven option when I Right Click on my project in Eclipse IDE. Hence when I create the java folder under the main folder, I am not able toUpdate Project Configuration` as mentioned here. Please advice
The Maven command mvn eclipse:eclipse generate the eclipse project files from POM.
The "-D" prefix in the argument means that it's a system property.
System property are defined like http://docs.oracle.com/javase/jndi/tutorial/beyond/env/source.html#SYS
mvn eclipse:eclipse -Dwtpversion=2.0 command convert the web based java project to maven based java project to support Eclipse IDE.
You can simple use given below command to clean and build your project:
mvn clean and mvn install
OR mvn clean install
Suggestion: Check maven is installed properly using command mvn --version.
Please try installing m2eclipse plugin (if you haven't done so yet) and nextly convert project to use maven behaviour through right clicking on project and choosing "convert to maven" option.
mvn eclipse:eclipse -Dwtpversion=2.0 -e clean install
run this instead. This builds your project by resolving dependencies
I'm creating a custom plugin for maven. Normally, when you run a normal Java program that depends on some .jar files, you put it in the command line as a classpath. In my plugin, there are some things it needs to know about that are in other .jar files.
When compiling the plugin for maven, how do I add classpaths to my custom maven plugin? Would I add it as a dependency in the pom.xml?
You can add things on the classpath of a plugin via defining dependencies for a plugin which works like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.1</version>
<dependencies>
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</plugin>
Apart from that it sounds strange that you need to define dependencies of a plugin during the runtime of the plugin.
I have a project that uses "system" scope to specify a jar file included in my project's WEB-INF/lib dir. This artifact is not in any of the maven repositories, so I must include it as part of my project. I do so with the following:
<dependency>
<groupId>com.example</groupId>
<artifactId>MySpecialLib</artifactId>
<version>1.2</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/MySpecialLib-1.2.jar</systemPath>
</dependency>
This has worked great for most things.
But now I'm trying to run some code on the command line (outside of my webapp, via a main() method I have added) and mvn exec:java can't resolve code in MySpecialLib because it's not included in the "runtime" classpath.
How can I either:
add MySpecialLib to the runtime classpath
or
tell mvn exec:java to also use the system classpath ?
I've tried mvn exec:java -Dexec.classpathScope=system, but that leaves off everything that's on runtime.
Use 'compile' scope to run maven exec plugin - mvn exec:java -Dexec.classpathScope=compile. This will include system-scoped dependencies.
As E.G. pointed out, the solution is to use the compile scope when running exec.
On each invocation:
mvn exec:java -Dexec.classpathScope=compile
or directly in the exec-plugin-configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
...
<configuration>
<classpathScope>compile</classpathScope>
</configuration>
</plugin>
Interesting to know that classpathScope=system drops runtime dependencies. I found that by including it as a plugin in the pom.xml works as an alternative. Could you please try and let me know if it works for you too?
So I added a system level dependency to commons-collection as an example like you have for your artifact:-
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>C:\\<some_path>\\commons-collections-3.0.jar</systemPath>
</dependency>
Then in the <build> tag I have the exec-maven-plugin plugin to be executed in the install phase:-
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.stackoverflow.test.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Then I ran mvn install. I also made sure com.stackoverflow.test.App class has some code that invokes a class from commons-collections-3.0.
Hope this helps.
The right answer is to use the maven-install-plugin and Put The Jar Into Your Local Repo. Or, better yet, run nexus or artifactory and use the deploy plugin to put the jar into there. System classpath is just a world of hurt.
I have a Java-Groovy Eclipse project that I build with Maven. I have added the Maven Groovy plugin to the pom.xml such that I can build/test the Java and Groovy sources on the command-line using Maven.
I would like to have some way to automatically generate the Eclipse .project and .classpath files from my pom.xml. If I run mvn eclipse:eclipse it seems to assume that it's a Java project, so there's no way to (for example) run the tests in src/main/groovy from within Eclipse.
I'm using the STS Eclipse distribution, which includes support for Groovy/Grails. All I'm missing is a way to automatically create the appropriate .classpath and .project files.
Thanks!
P.S. I know IntelliJ is better, but I don't have a license
Here is configuration I found that works when Java calls Groovy code
and when Groovy calls Java code fitting good within groovy eclipse IDE plugin (nature).
There is no need for additional source folders for groovy. It just works!
Using:
mvn clean install eclipse:clean eclipse:eclipse
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<extensions>true</extensions>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
You should try the Groovy-Eclipse m2eclipse integration. It is available here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
With this installed, your maven projects will be automatically configured as groovy-eclipse projects when you import them into your workspace.
If you would like to create a Groovy project just by calling mvn eclipse:eclipse you have to configure your project. As follows a snippet how you configure your maven eclipse plugin so that your project becomes a Groovy project in Eclipse. That snippet must go into your projects pom.xml by the way.
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceIncludes>**/*.groovy</sourceIncludes>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
...
When you now call mvn eclipse:eclipse maven creates the .project and .classpath files. .project contains the new project nature what makes it a Groovy project and .classpath contains the */*.groovy* what makes Eclipse treating any file that ends on .groovy as a source file.
Please see also http://maven.apache.org/plugins/maven-eclipse-plugin/examples/provide-project-natures-and-build-commands.html
There is another best way to create maven groovy project. Please follow below steps:
Navigate to https://start.spring.io/ from your browser.
Select project as maven and language as groovy as shown below.
Select other options as per your build requirement like packaging, java version and project name.
Now click on Generate radio button at the bottom and a maven groovy project will be downloaded.
Open Eclipse and import the downloaded maven project and it's ready to use for your groovy scripting with maven integration.