Maven build is affected by Eclipse .classpath file - java

Maven build is affected by Eclipse .classpath file content.
I have 2 lines in .classpath, that I don't want maven to know about (src/old/java & src/test/manual).
<!-- Disable these 2 lines below to see how project compiles with Maven on Jenkins-CI or locally
-->
<classpathentry including="**/*.java" kind="src" output="target/old-classes" path="src/old/java"/>
<classpathentry excluding="**/.svn/" including="**/*.java" kind="src" output="target/test-classes" path="src/test/manual"/>
However maven is taking that. And executes those manual tests. And of course fails.
How to disable this behavior?
I use Maven 3.0.4. build section of pom.xml is below.
<build>
<plugins>
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>2.3.2</version> -->
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<!-- http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html
<plugin> RAW
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>some/relative/path</directory>
<includes>
<include>**/*.tmp</include>
<include>**/*.log</include>
</includes>
<excludes>
<exclude>**/important.log</exclude>
<exclude>**/another-important.log</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
-->
<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>target/fun_base-1.0-SNAPSHOT</directory>
<excludes>
<exclude>**/*.jar</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
<!-- http://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<javadocVersion>${java-version}</javadocVersion>
<source>${java-version}</source>
<verbose>false</verbose>
</configuration>
</plugin>
<!-- http://maven.apache.org/plugins/maven-pmd-plugin/examples/targetJdk.html -->
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<targetJdk>${java-version}</targetJdk>
</configuration>
</plugin>
</plugins>
</build>
<!-- http://maven.apache.org/plugins/maven-pmd-plugin/examples/targetJdk.html -->
<reporting>
<plugins>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<targetJdk>${java-version}</targetJdk>
</configuration>
</plugin>
</plugins>
</reporting>

Related

Maven: JavaFX: Bundle libs in one Jar File

I need a solution to pack all lib-files into the executable jar-file.I use Maven and the Maven plugins javafx-maven-plugin, maven-compiler-plugin and maven-surefire-plugin. I haven't found a solution for my problem based on these plugins yet.
I hope someone can help me. Here are the configurations of the plugins.
<build>
<plugins>
<!-- https://github.com/javafx-maven-plugin/javafx-maven-plugin -->
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.4</version>
<configuration>
<mainClass>${exec.mainClass}</mainClass>
<verbose>true</verbose>
<jfxAppOutputDir>${project.basedir}/target/output</jfxAppOutputDir>
<jfxMainAppJarName>${project.name}.jar</jfxMainAppJarName>
<allPermissions>true</allPermissions>
<manifestAttributes>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Specification-Vendor>${project.organization.name}</Specification-Vendor>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${build.number}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Implementation-URL>${project.organization.url}</Implementation-URL>
</manifestAttributes>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
What you are looking for is called uber-jar or shaded jar. You can use the following maven-plugin:
Maven Shade Plugin
Selecting Contents for Uber JAR

How to create single jar with dependencies in maven

I am trying to create single fat jar using maven assembly plugin but somehow after running maven clean install it give 2 jars, one is client-1.0-SNAPSHOT.jar and other one is client-1.0-SNAPSHOT-jar-with-dependencies.jar.
I am only interested to create a jar with dependencies so dont know why the other jar is also creating by this assemble plugin.
Can someone tell me how to eliminate this jar Or should i use some other maven command rather than clean install ?
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.app.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- overwrite! -->
<overwrite>true</overwrite>
<outputDirectory>${project.basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

how to modify the maven jar-plugin to fix the MissingResourceException error

I'm really bad at maven and I get that MissingResourceException error:
So and here is my pom.xml (build):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath>
<mainClass>org.jis.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.14</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.4.1</version>
</dependency>
</dependencies>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>${basedir}/src/test/resources/checkstyle_swt1.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>src/assembly/src.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
my src.xml:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>src</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>.gitignore</source>
<destName>gitignore.txt</destName>
</file>
</files>
<fileSets>
<fileSet>
<outputDirectory/>
<includes>
<include>${project.basedir}/src/main/java/org/jis/generator/Consumer.java</include>
<include>${project.basedir}/src/main/java/org/jis/generator/Element.java</include>
<include>${project.basedir}/src/main/java/org/jis/generator/Generator.java</include>
<include>${project.basedir}/src/main/java/org/jis/generator/LayoutGalerie.java</include>
<include>${project.basedir}/src/main/java/org/jis/generator/Producer.java</include>
<include>${project.basedir}/src/main/java/org/jis/generator/TableGalerie.java</include>
<include>${project.basedir}/src/main/java/org/jis/listner/CloseListner.java</include>
<include>${project.basedir}/src/main/java/org/jis/listner/ExitListner.java</include>
<include>${project.basedir}/src/main/java/org/jis/listner/MenuListner.java</include>
<include>${project.basedir}/src/main/java/org/jis/options/Options.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/dialog/AboutBox.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/dialog/GallerieDialog.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/dialog/Layout.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/dialog/OptionsEdit.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/FileTree.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/List.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/Menu.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/Preview.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/Status.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/Thumbnail.java</include>
<include>${project.basedir}/src/main/java/org/jis/view/Toolbar.java</include>
<include>${project.basedir}/src/main/java/org/jis/Main.java</include>
<include>${project.basedir}/src/main/java/org/jis/Messages.java</include>
</includes>
</fileSet>
<fileSet>
<directory>target</directory>
<includes>
<include>pom.xml</include>
</includes>
</fileSet>
<fileSet>
<directory>target</directory>
<includes>
<include>changelog.xml</include>
<include>changelog.html</include>
</includes>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
I'm not sure what I'm doing wrong here but I read at this post that it could happen because my properties and class files are at the same place in my jar file.
but how do I fix this in my pom.xml?
Edit:
The error message as text
Exception in thread "main" java.util.MissingResourceException: Can't find bundle
for base name org.jis.messages, locale en
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source
)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at org.jis.Messages.<init>(Messages.java:42)
at org.jis.Main.<init>(Main.java:86)
at org.jis.Main.main(Main.java:201)

Izpack Maven plugin Invalid base directory on Eclipse Maven project

When I'm going to Maven-install my project with pom
<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>${basedir}/src/main/izpack</sourceDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/izpack</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- Configure the compiler to use Java 1.5 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!-- Have project dependencies be picked up by izPack when its compiler runs -->
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>5.0.0-rc4</version>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-panel</artifactId>
<version>5.0.0-rc4</version>
</dependency>
</dependencies>
<!-- mvn help:describe -DgroupId=org.codehaus.izpack -DartifactId=izpack-maven-plugin -Dversion=5.0.0-beta11 -Ddetail -->
<configuration>
<installFile>${staging.dir}/install.xml</installFile>
<attach>false</attach>
<kind>standard</kind>
<descriptorEncoding>UTF-8</descriptorEncoding>
<izpackBasedir>${staging.dir}</izpackBasedir>
<customPanelDirectory>${staging.dir}</customPanelDirectory>
</configuration>
<executions>
<execution>
<id>standard-installer</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Do not deploy any of the installer artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<staging.dir>${project.build.directory}/staging</staging.dir>
</properties>
Failed to execute goal org.codehaus.izpack:izpack-maven-plugin:5.0.0-rc4:izpack (standard-installer) on project Izpack-Installer: Failure during compilation process: Invalid base directory: workspace/myproject/target/staging
The above error is making my whole day waste... please post working pom of izpack Maven plugin which support console installation in Linux.
Note: I placed my install.xml in src/main/izpack/install.xml as well as src/main/resources/install.xml.
Finally after end of the day got answer...:)
<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>${basedir}/src/main/resources</sourceDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- Configure the compiler to use Java 1.7 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Have project dependencies be picked up by izPack when its compiler runs -->
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>5.0.0-rc4</version>
<configuration>
<installerFile>${basedir}/target</installerFile>
<izpackBasedir>${staging.dir}</izpackBasedir>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
</configuration>
<executions>
<execution>
<id>izpack</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Do not deploy any of the installer artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<staging.dir>${project.build.directory}/staging</staging.dir>
</properties>
"staging" directory in target folder is created manually....:)

How to properly set up multi profile maven project?

Hey, I'm talking about profiles within pom.xml of a project. Could please anybody explain to me, why if I have 2 profiles in pom definition and I run test phase from one of the profiles, both the Main method is executed and all the tests are run by surefire plugin ? I mean, even the surefire plugin runs all the tests, even though it is within a different profile ?
mvn test -Pcode-generator
the first one,code-generator, is just for Main methods execution and the second one for the rest of the project.
<profiles>
<profile>
<id>code-generator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>cz.instance.transl.Main</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>default</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<warName>${war.file.name}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<useFile>false</useFile>
<argLine>-Dportal.test=generic
-Dwebdriver.chrome.driver="/opt/google/chrome/chromedriver"
-Dwebdriver.development=true
-Dwebdriver.firefox.useExisting=true
-Dwebdriver.firefox.profile=webdriver
-Dwebdriver.reap_profile=true
-Dsurefire.useFile=false
-Xmx2048M
-XX:MaxPermSize=1048M
-XX:+CMSClassUnloadingEnabled
</argLine>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>META-INF/log4j.xml</value>
</property>
</systemProperties>
<includes>
<include>cz/instance/transl/tests/selenium/*Test.java</include>
</includes>
<excludes>
<exclude>cz/instance/transl/tests/sample/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.7.1</version>
<!-- <configuration> <useFile>false</useFile> </configuration> -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
<resources>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>service.properties</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>profiles/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
The surefire plugin is one that runs by default for a java project. You have a number of options:
Add the surefire plugin to your code-generator profile and override it not to run.
Run with -DskipTests.
Specify only the goal you want to run, instead of running a full maven build.

Categories

Resources