Clean all files except target in maven - java

In maven is it possible to clean all files inside project directory except target directory after maven compile step? How can I setup this?
My requirement is something like this -
I run maven compile command which generates classes file under target directory.
Now I want to copy only generated target folder and pom.xml to another directory and build jar/war from that location, can I do something like this?
Also can maven copy a external properties file(outside of project) to projects WEB-INF/classes folder?

Related

how to run gradle with class files inside the build folder?

I am creating RESTAPI application using gradle. I would like to deploy to server without the original java source code.
./gradlew build will generate build folder, however, ./gradlew run will also generate build folder and run the class files, resources folder and jars in build folder.
Is it possible to skip the generate build folder and run the build folder directly? If not, how can i start gradle with class files, jars and resources folder?

In maven pom.xml, how to specify that I want to copy a ".xml" file into my target folder?

I'm building a mybatis project, under my src/main/java I have folder structure like this:
java
--mypackage
--beans
UserBean.java
--mapper
UserMapper.java
UserMapper.xml
--service
UserMapperServer.java
--resources
when I run "mvn compile", the java files will be compiled into "target/classes" folder, but my "UserMapper.xml" file is not automatically copied into "target/classes/mypackage/mapper" folder, so the program will fail to start/debug.
If I move the file into "resources" folder, then "mvn compile" copies it into "target/classes" folder, but not "target/classes/mypackage/mapper" folder, still not able to run/start.
So my question is, in "pom.xml" how to specify my required "copy" file instruction?
Thanks a lot.
Maven convention suggests putting the sources into src/main/resources folder
In this case maven will pick them an put to jar automatically, no need to use src/main/java for this.
Now, resources folder can also have inner folders
So, your layout should be (to comply with maven conventions):
java
--mypackage
--beans
UserBean.java
--mapper
UserMapper.java
--service
UserMapperServer.java
--resources
resources
--mypackage
--mapper
UserMapper.xml

Eclipse misplaces maven resources in output jar

I have a maven project loaded in eclipse that when I go to export it as jar, the src/main/resources files always end up in the /resources directory inside the jar. I found a kludge to get around this by putting all my resources in the root directory of the project, but it's getting very messy very fast. Is there any way to configure it so the resources output to root of jar?
you dont export a maven project as jar.
you clean package it and you get the resulting jar at the target folder.
right click the project's pom.xml and run it as maven build.

Why does Maven create two jars for same source in target and groupId directory

I have a Maven project with the src and pom having following groupId and artifactId
<groupId>com.useless.coders</groupId>
<artifactId>nonsense-program</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
Now when we build the jar using mvn clean install, a target folder is created with the jar name and version as nonsense-program-0.0.1 . When I navigate to .m2 repository in the folder structure com/useless/coders/ I can see the same jar is also created with extra metadata information in maven-metadata-local.xml. I know the purpose of Maven repository and as in target directory we house all output of the build with generated .class files with jar and/or libs.
But I am curious to know why we maintain two jar copies of same source one in target directory and other in the groupId path directory. Wouldn't have we saved some space.
It's because you instructed Maven to do so. If you call mvn clean package (instead of install), only the Jar under target is created. The install phase tells Maven to save the resulting Jar in the local repository.

Issue creating Jar files (repository is from github)

Creating a Jar file:
I want to create Jar files from a Github Java repository. How can I create below Jar files?
Jars to create:
geo-ip-java.jar
hive-udf-geo-ip-jtg.jar
Git URL: https://github.com/edwardcapriolo/hive-geoip
I found we can create them as below syntax, but seems it is using maven to compile them:
jar cf jar_file.jar file.java
As this is a maven project (as seen that the file pom.xml exists) you can create the target artifact (in your case the jar file) by simply executing mvn package.
If you want to use the jar file in another maven project (as dependency) then it is more usefull to use mvn install as this also installs the artifact in your local repository.

Categories

Resources