I want to copy files in ".jenkins" or in "Temp" direcotry.
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resource-one</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>C:\Users\user\.jenkins</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>htmlTemplate.html</include>
<include>Chart.js</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
This is how my pom.xml looks like for now. It is working for me on my local machine, but it won't work for another user.
This is what I want:
<outputDirectory> relative path to Temp </outPutDirectory>
Question: How can I ensure that the file is always copied in "temp" or in ".jenkins" folder? Is there any variable for that?
In Maven you can use Java properties as Maven properties for a build.
Maven exposes all properties from java.lang.System. Anything you can retrieve from System.getProperty() you can reference in a Maven property
So, in your case you could have the following:
<outputDirectory>${java.io.tmpdir}</outputDirectory>
And the output directory will point to the user temporary directory based on the host OS. For instance, in Windows 7 it would be
C:\Users\<user_Id>\AppData\Local\Temp
For a full list of Java properties, check official documentation, from which:
java.io.tmpdir: Default temp file path
You may also be interested in the user.home
user.home: User's home directory
So you probably wanted to point to ${user.home}\.jenkins.
As said in the above comments, using hardcoded path is a really bad solution.
One solution should be to create a .jenkins folder in the /target folder:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/.jenkins"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
And to use this .jenkins folder as an output folder:
<configuration>
<outputDirectory>${project.build.directory}/.jenkins</outputDirectory>
...
</configuration>
It will work on all the build machines (developer laptop or server).
In addition to suggested answers, you can also use HOMEPATH system variable, which is by default set on Windows systems.
<outputDirectory>${HOMEPATH}/.jenkins</outputDirectory>
HOMEPATH resolves to \Users{username}
Related
I'm using Maven in IntelliJ and I want to include a 'resources' directory in my build output alongside the JAR and/or in whatever directory IntelliJ uses as the cwd when running my project. I don't want these files in the JAR/Classpath, just alongside the final built project.
The idea is that then, my project can refer to files named things in src/ext-resources/foo.txt as resources/foo.txt.
I'm currently using the following instruction in pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/resources</outputDirectory>
<resources>
<resource>
<directory>src/main/ext-resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
However, this doesn't appear to actually make it accessible, and doesn't seem to be copying these files at all. At one point, my config resulted in the subdirectories of src/ext-resources being copied into target/classes for some reason, but they aren't being copied into target/resources no matter what.
How do I make maven copy this folder into my final output directory?
I have maven project which contains Java classes and Windows/Linux scripts. Whenever I made some changes to the Java source code, I then execute 'mvn install' and call those scripts to test my changes. Those scripts therefore points to Maven repository to find the JARs. For instance,
SET app=%M2_REPO%\A\B\C\1.0-SNAPSHOT\C-1.0-SNAPSHOT.jar
SET app1=%M2_REPO%\E\F\G\1.0-SNAPSHOT\G-1.0-SNAPSHOT.jar
java -classpath !app!;!app1!;!app2!;!app3! !main_class! %1 %2 %3 %4
Now, the requirement is to
1. package all the jars and scripts into one ZIP file;
2. jars and scripts have to be at the root level in this ZIP file.
I just wonder if it is possible to automatically set app at
app=%M2_REPO%\A\B\C\1.0-SNAPSHOT\C-1.0-SNAPSHOT.jar
at compile phase
and automatically change it to
app=C-1.0-SNAPSHOT.jar
at install phase.
If yes then how? Thanks in advance.
You should use maven-resources-plugin with two separate setting files at two different phases:
<executions>
<execution>
<id>compile-settings</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>something</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>resources/compile.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>package-settings</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>something</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>resources/package.properties</filter>
</filters>
</configuration>
</execution>
</executions>
I wanted to create my jars with wars with that should include source file(.java file) parallel to .class file in the generated jar using maven. (I know there are some plugins available to generate a separate xyy-sources.jar file. But I dont want to create a seperate source jar. I need a single jar file with both .class and .java file exists parallel)
You only have to add resources under build tag.
For example.
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
</build>
Now every jar and war file you creat would contain .java files also. :)
I'm still not sure I understand why you would want to do this, but you could use the maven-resource-plugin and specifically its copy-resource goal to copy your java files to any location within your build directory. So for example to copy them to the classes folder which then gets included in the jar that is built automatically you could do the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/src-files-location</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I am not sure if including .java adjacent to .class is a very good idea. Any specific reason you want to do that?
If you need to include sources, you can create a separate source jar (which is not you asked for, but is recommended way) like this by executing mvn package
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Does this help? http://maven.apache.org/plugin-developers/cookbook/attach-source-javadoc-artifacts.html
I have a some perl file in my src/main/java/com/pac/report.pl which I want to package as part of my classes in the jar file.
Using maven maven-jar-plugin include directives, I have tried below and various other suggestions I pulled off the web, but doesn't copy the perl file as part of my classes in the jar file. Does anyone know what I am doing wrong.
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
EDIT
Also let me point out that I don't want to place the file in the resource directory due to legacy call and dependent reasons.
That is because the classes packaged into your jar aren't taken from src, but rather from target (specifically /target/classes), and the compiler completely ignores your non-java file.
Try placing your file in src/main/resources/com/pac/report.pl and it should be packaged into the jar (with the relative path of /com/pac/report.pl) since thats the default location where the resources plugin looks for additional files to add to /target before the jar plugin runs.
EDIT - or, if you dont want to / cant do this the way maven expects, you could manually bind an execution of the resources plugin to the lifecycle to pick up your file and copy it over to target. something like this:
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>compile</phase> <!-- or later -->
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<!-- path to your *.pl file here -->
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
Fingers crossed you can help me!
I am using SmartSprites to combine the PNGs on my landing page into one, so that it will load quicker.
SmartSprite will examine your CSS files, generate a CSS Sprite image, and create a new CSS file which will use this sprite image instead of the originals. What I want to do is replace the original CSS file with the SmartSprite one automatically during my maven WAR build.
So here's what I would like to happen:
SmartSprite scans my CSS file: mystyle.css
SmartSprite create a sprite image, and creates a new mystyle-sprite.css file, which references the new sprite image.
I want to copy mystyle-sprite.css over mystyle.css before the WAR is built, so that I don't have to change any of my references in the JSP files.
Both files are located in the output directory (target/myproj/css). There doesn't seem to be any flag in SmartSprite to override the original file, so I guess it had to be done post-processing.
Below is the maven plugin configuration I'm using for SmartSprite.
<plugin>
<groupId>org.carrot2.labs</groupId>
<artifactId>smartsprites-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>spritify</goal>
</goals>
</execution>
</executions>
</plugin>
I'm afraid you won't find anything simpler or more elegant than Maven AntRun Plugin with something like this:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<target>
<copy file="${project.build.directory}/mystyle-sprite.css"
tofile="${project.build.directory}/mystyle.css" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can use the Maven WAR plugin:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory><!-- Your output directory --></directory>
<targetPath><!-- The target location of the files below --></targetPath>
<includes>
<include><!-- file pattern --></include>
<include><!-- file pattern --></include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
You should also configure SmartSprites to use a different output directory to preserve the original CSS filename. Try the output-dir-path option with an empty css-file-suffix value.