I am looking to start a project using Vaadin and I want to use Maven as the repository manager, but I am having a lot of trouble starting the Maven project.
I tried creating a project in IntelliJ using the vaadin-archetype-application-example and it doesn't create any directory.
I also tried creating the project with the mvn commands and I found a lot of troubles too. When I create the Maven project this error is shown in the log:
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
[ERROR] Maven execution terminated abnormally (exit code 1)
How can I deploy a Maven project with IntelliJ? I have the Maven plugin installed and the mvn command seems to work just fine.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.imtoolazytoadmin</groupId>
<artifactId>ImTooLazyToAdmin-master</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Use this command to create your project and then import it to your IDE.
$ mvn archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-application \
-DarchetypeVersion=7.5.9 \
-DgroupId=your.company \
-DartifactId=project-name \
-Dversion=1.0 \
-Dpackaging=war
More info about creating Vaadin projects in IntelliJ here.
Related
I built a server template in java and now i need to compile and run it using MAVEN.
this is my POM:
<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>bgu.spl</groupId>
<artifactId>spl-net</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
-<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>spl-net</name>
</project
When I run mvn compile it all works. but then i go to test it with: mvn exec:java - Dexec.mainClass=”bgu.spl.net.impl.BGRSServer.ReactorMain” - Dexec.args=”<port> <No of threads>” and it gives me a class not found exception. I looked in the target directory and this exact main was indeed there, it just refuses to run.
Turns out there was nothing wrong with my code. I failed to realize that in ubuntu, the command: mvn exec:java - Dexec.mainClass=”bgu.spl.net.impl.BGRSServer.ReactorMain” - Dexec.args=”<port> <No of threads>” simply doesn't work. the correct command would be: mvn exec:java - Dexec.mainClass=bgu.spl.net.impl.BGRSServer.ReactorMain - Dexec.args=<port> <No of threads>
I installed the Nexus repository in my notebook, then upload a snapshot project in it. This is how it looks:
Now, I'm trying to build a Docker image, with another project that has the previous project as a dependency. This is my Dockerfile:
FROM maven:3.5.2-jdk-8-alpine AS MAVEN_BUILD
COPY settings.xml /usr/share/maven/ref/
COPY pom.xml /build/
RUN echo $(route -n | awk '/UG[ \t]/{print $2}')
RUN sed -i "s/localhost/$(route -n | awk '/UG[ \t]/{print $2}')/g" /build/pom.xml
COPY src /build/src/
WORKDIR /build/
RUN mvn package -DskipTests=true
# Other stuff that doesn't matter...
I've added this lines to pom.xml to resolve dependencies from Nexus (locahost is replaced (see Dockerfile) with docker gateway IP):
<repositories>
<repository>
<id>maven-group</id>
<url>http://localhost:8081/repository/maven-group/</url>
</repository>
</repositories>
It works as expected until maven needs to dowload my own library dependecy, the one uploaded to Nexus, failing with the message:
[ERROR] Failed to execute goal on project springboot-servicio-producto: Could not resolve dependencies for project com.abarazal.springboot.app.producto:springboot-servicio-producto:jar:0.0.1-SNAPSHOT: Could not find artifact com.abarazal.springboot.app.commons:springboot-servicio-commons:jar:0.0.1-SNAPSHOT in maven-group (http://172.17.0.1:8081/repository/maven-group/) -> [Help 1]
In pom.xml the dependency is declared as:
<dependency>
<groupId>com.abarazal.springboot.app.commons</groupId>
<artifactId>springboot-servicio-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
What am I missing to make it work?
Check if you have more than 10% free disk space.
This may be an issue caused by elastic search.
I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports
I have source code for a framework, let's call it my-framework. It provides various packages, including com.not_telling.framework.db.
I have a pom.xml file for this framework:
<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.not_telling</groupId>
<artifactId>my-famework</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>my-framework Maven Library</name>
<url>http://maven.apache.org</url>
<!-- more things here... -->
</project>
I can compile this and install it to my local repository cache, using this command:
mvn install
End of the install log:
[INFO] Installing C:\Users\MyUserName\my-framework\backend\target\my-framework.jar to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\MyUserName\my-framework\backend\pom.xml to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Then I have another project, that tries to use this as a dependency:
<dependency>
<groupId>com.not_telling</groupId>
<artifactId>my-famework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
The compilation phase of this project fails with this message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure:
[ERROR] /C:/Users/MyUserName/workspace/my-project/backend/src/main/java/com/not_telling/some_example.java:[13,17] package com.not_telling.framework.db does not exist
Why is that? Maybe because the jar is in the repository cache, but not in a local repository?
This question is a follow up of absolute maven pomderived entry added to classpath - I realized that instead of doing magic with relative source directory references, I need to make a separate module, but I'm facing this problem.
It was bleeding from numerous wounds. These needed to be fixed:
move source files from under src/ to under src/main/java, in both the framework and the application project
change the group and the artifact id to match the package name E.g. for a package that is named "com.not_telling.framework" I had to use groupId=com.not_telling and name=framework.
The dependency scope was wrong in the application's pom file. I had to remove test
Now it works from command line I can do "mvn install" for the framework, and then "mvn package" for the applications.
The only problem left is that the application cannot be compiled from eclipse, I had to remove all linked source folders / build paths in the application project to the framework.
I start learning packaging for several distros (currently Cygwin and Debian).
They have requirement to build system to allow out-of-tree build (synonym out-of-source build):
http://wiki.debian.org/UpstreamGuide#Out-of-Tree_Builds
To work-around "dumb" build system for example cygport recommend use lndir (from xutils project):
lndir ${S} ${B}
cd {B}
...build-commands...
I read mvn(1) man page but doesn't found anything appropriated. Next I just try:
$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
...
$ pwd
/maven/simple
$ ls
my-app
$ mvn -f my-app/pom.xml compile
...
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) # my-app ---
[INFO] Compiling 1 source file to /maven/simple/my-app/target/classes
As you can see target directory created in source root hierarchy while I look for a way to avoid this.
Is it possible out-of-tree build with maven? And how?
You could do like this to get it in your current working directory:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q13173063</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<buildDir>${user.dir}</buildDir>
</properties>
<build>
<directory>${buildDir}</directory>
</build>
</project>
Then you can issue
mvn -f my-app/pom.xml compile
And it will give you your classes in the current working directory.
And easily change to another output directory:
mvn -f my-app/pom.xml -DbuildDir=/tmp/build compile
It might be as simple as having a
<build>
<directory>/your/build/directory</directory>
</build>
in your pom.xml. /your/build/directory need not be in the source tree and can be parameterized using the usual ${...} syntax.
Cheers,