Maven won't compile the classes in test folder - java

I'm trying to have some end-to-end test for the component I'm developing using Java. So, these classes in test are not Unit Tests, and I only want to run them as a normal Java class.
I have my sources in the src\main\java folder and the tests inside src\test\java. The test has two Java classes, one is a util class and the other one extends a class in main and also has the main method. Ultimately, I need to run this main method.
I created two pom files, one for the main project and one for running the test. The only difference in the test pom file was the mainClass property.
When I had the test classes inside src\main\java, maven compiles them and I was able to run them without any issue.
Because having tests inside the src\main\java folder is a bad practice, I wanted to move it to the src\test\java folder. But then it doesn't work. It compiles the project but doesn't compile the test classes (obviously because now it's not inside the src\main\java folder). So I added the test to the classpath scope in the test pom file as below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.my.company.project.MyTestClass</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
But this doesn't work.
So I tried the solution provided by maven itself, but it's the same. It creates the jar file with my test class as the main class in the manifest file. But there are is no such class, nor classes from the main inside of the jar file. And I get the below error when running the jar file.
Could not find or load main class com.my.company.project.MyTestClass
My end goal is to be able to compile and run my Test class (to test the main class) using maven.
Can you suggest me a way to achieve this?
EDIT:
pom.xml
<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.my.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
...
</properties>
<developers>
...
</developers>
<dependencies>
...
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</plugin>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.my.company.project.MyClass</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.my.company.project.MyClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
EDIT 2:
According to the comment from #notionquest, I updated the POM file. Now the test classes are getting compiled, but not available inside the jar file. So, it still gives me the error:
Error: Could not find or load main class com.trivago.visual.debezium.test.ChangeDataCaptureSenderTest

Related

pom.xml that works (Could not find or load main class/no main manifest attribute)

I have spent several hours on this and I'm unable to get it done. For a Maven/JavaFX-Application I am trying to get an executable jar. But whenever I build it with its dependencies and execute it with java -jar Kvn-jar-with-dependencies.jar I get one of these errors:
When executing the Fat Jar:
Error: Could not find or load main class com.qohelet.kvn.MainApp
When executing the Jar which apparently doesn't contain the dependencies
no main manifest attribute, in Kvn.jar
I use netbeans 8.2 for development (this is one of the last versions which can run with the OpenJDK 1.8.0) and I can run my project any time using (or better, Netbeans uses it):
cd /home/qohelet/Projekte/Kvn; JAVA_HOME=/home/qohelet/jdk1.8.0_111 /home/qohelet/netbeans-8.2/java/maven/bin/mvn "-Dexec.args=-classpath %classpath com.qohelet.kvn.MainApp 'USER' 1 'Indonesia'" -Dexec.executable=/home/qohelet/jdk1.8.0_111/bin/java org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
There had been an issue with the obtaining the dependencies due to the change by mvn to ssh, but I didn't even have maven installed before, it still worked. (Maven dependencies are failing with a 501 error), now one of the addresses in the project header contains a https instead of a http but I don't think this is much of an issue.
Currently the pom.xml looks like this, this is an edited version of https://maven.apache.org/plugins/maven-assembly-plugin/usage.html:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.qohelet</groupId>
<artifactId>Kvn</artifactId>
<version>2.2</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>
<build>
<finalName>Kvn</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.qohelet.kvn.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Various -->
</dependencies>
<name>Kvn</name>
</project>
This version gives me the mentioned error.
I found a different suggestion where the -Section is set up like that which apparently worked for a while, but for some reason it doesn't seem to be advised as Netbeans complains:
Problem: Project Problem: Project's main artifact is processed through
maven-shade-plugin, resolvable by:
org.netbeans.modules.maven.problems.ProblemReporterImpl$MavenProblemResolver#a5534d
unresolved
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.qohelet.kvn.MainApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
A few months ago the project could still be built with the following -Section but this was mostly a result from trial and error until I had a working result:
<build>
<finalName>Kvn</finalName>
<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>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.qohelet.kvn.MainApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am not sure if I interpret this correctly but can it be due to version changes in Java?
SO provides a lot of answer, but I am not able to get anything to work.
https://stackoverflow.com/a/589111/2516892 gets me the exact same error:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.qohelet.kvn.MainApp </mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Similar to https://stackoverflow.com/a/4323501/2516892 with the following build section which doesn't return a Fat Jar but the same error.
What is the state of the art? How should it be done properly?
Thank you
Edit (1):
The structure of the Jar looks fine to me. 22Mb seems to be a reasonable size too. It a folder /com/qohelet/kvn/ which contains a MainApp.class
Using https://stackoverflow.com/a/574650/2516892 and compiling with
mvn clean compile assembly:single
weirdly results in a set of errors like
package javafx.beans.value does not exist
Which is odd as JavaFX is installed and I can run the program without any issue.
Netbeans is not doing much different:
cd /home/qohelet/Projekte/Kvn; JAVA_HOME=/home/qohelet/jdk1.8.0_111 /home/qohelet/netbeans-8.2/java/maven/bin/mvn clean install
But this results in a jar with only 254Kb, which I assume doesn't contain the dependencies. Including the make-assembly-part just creates the same error.
Using the 2nd one listed here https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html is just the same error: Error: Could not find or load main class com.qohelet.kvn.MainApp, the archive is slightly smaller (19Mb) and again it contains a folder-structure: /com/qohelet/kvn/ which contains a MainApp.class

Maven assembly jar execution Could not find or load main class Caused by: java.lang.ClassNotFoundException

I have been trying, for several days now, to create an executable jar file for my muli-module maven project, sadly I have had no luck on doing it.
I know that there are a lot of similar questions already, but, even by following the answers, i cannot manage to run the jar I make.
I am using the maven-assembly plugin, so that my jar contains all the required dependencies, here is the pom:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>tam-authentication</artifactId>
<name>tam-authentication</name>
<description>authentication tam project</description>
<parent>
<groupId>com.netcomgroup.eu</groupId>
<artifactId>TAM</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>11</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>"fully qualified class name"</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
...
dependencies from other modules
...
</dependencies>
</project>
futhermore i have another probably related problem regarding jar creation with a common library included:
using Eclipse as IDE, whenever I run as > maven install on the multimodule project, I often get jars failing over correct imports, that I need to delete and import again to complete the java building process correctly. Sometimes i simply must run maven install several times in a row to make the jar building process succeed.
I don't know if the second problem is related but i guess there is some mistake I cannot see in the multi module project jar building.
First of all, as per your pom.xml you did not provide the fully qualified Main class name in your dependency. Second if you provided the Main class name, then after "mvn clean install", it would create 2 jars - one with artifact name and one with "jar-with-dependencies" and you have to user "jar-with-dependencies".
Also i don't think you need to use pluginManagement tag as an extra step. I have just modified a bit your pom below, please try this and check.
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<artifactId>tam-authentication</artifactId>
<name>tam-authentication</name>
<description>authentication tam project</description>
<parent>
<groupId>com.netcomgroup.eu</groupId>
<artifactId>TAM</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>11</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>{Your fully qualified Main class eg - abc.cde.Main}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
...
dependencies from other modules
...
</dependencies>

Maven custom directory structure - no sources to compile despite specifying sourceDirectory

I am using a custom directory structure and have specified the directory in sourcedirectory tag. But still I get the message No sources to compile. Although the build is successful.
My directory structure:
So instead of src/main/java, I am using java. (And I have a reason to do that, so right now it's not possible to switch to src/main/java)
Here's my pom.xml:
<artifactId>application</artifactId>
<name>application</name>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
</properties>
<build>
<sourceDirectory>java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>**/old/**/*.java</exclude>
</excludes>
<includes>
<include>java/com/**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>**/old/**/*.java</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.start.Start</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
When I run command mvn clean package, I get following output:
The source is not compiled and resultant jar is empty. All the sources I have referred for using custom directory structure with maven say that using sourceDirectory should solve the problem. But in my case it doesn't solve
EDIT
I am using custom directory structure as using standar directory structure did not work for me. Hers' my question related to that:
Getting error in linking a source folder in eclipse maven
EDIT2:
I am linking source in java directory. That is, on the file system, application->java does not exist, but in eclipse through link source option, I have added the Java source folder from a different directory. Therefore it appears in eclipse. Also I have run maven commands with mvn command line as well as through eclipse.
If I understand your issue correctly, You have an application folder and the actual source (java) folder is from somewhere else in the file system.
And you linked the external folder as java source through eclipse for compilation.
By linking in Eclipse, maven will not automatically know where the source files are. Maven follows standard directory structure for looking up java and test files.
You can use this Build Helper plugin to customize the way maven looks up sources.
An example talked here
This is your problem: <include>java/com/**/*.java</include>
You should not include the sourcedirectory, just the paths relative to it.
Follow these steps of this working example and compare it step by step with your project to figure out what's wrong:
create a folder.
create inside the folder a pom.xml with the following content:
<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.yourdomain.yourproject</groupId>
<artifactId>yourapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>yourapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.yourdomain.yourproject.content.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<dependencies>
<dependency>
<groupId>org.jvnet.wagon-svn</groupId>
<artifactId>wagon-svn</artifactId>
<version>1.12</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
create this folder structure inside your root folder:
src/main/java/com/yourdomain/yourproject/content/
create a Main.java in content folder with the following content:
package com.yourdomain.yourproject.content;
public class Main
{
public static void main(String[] args)
{
System.out.println("HELLO");
}
}
go back to your root folder and execute mvn clean install
a target folder will be created with the jar in there.
you can execute it with java -jar target/yourapp-1.0-SNAPSHOT.jar

How do I make IntelliJ IDEA automatically extract a dependency to the artifact jar?

Let's say I'm adding the following dependency to my pom.xml:
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
I can now use the Ini class as expected, but if I try to build the jar and run it, it will give me a "noclassdeffounderror" error. When I check the content of the jar, it does not contain org/ini4j.
I was able to fix this by going into File -> Project Structure -> Artifacts
If I want to add another dependency, I'll have to do this every time, which is quite tedious (I didn't need to do this on NetBeans). I then tried to use the following plugins (which I used on NetBeans) to have Maven create a jar with dependencies automatically.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
On NetBeans, this automatically adds all dependencies to the jar file, but it doesn't do anything on IntelliJ IDEA. I have no idea what I'm doing anymore; nothing works. How can I make IntelliJ IDEA automatically extract a dependency into the output root?
Dose your intellij use the same version on maven that your Netbeans uses? if it checks fine, try another plugin for making a fat jar such as the folowing:
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

Eclipse / Maven: "Could not find the main class" Errors While Building Executable JAR

Updated: "Could not find the main class" turned out to be a red herring: In the line immediately before public static void main(String[] args) my class attempts to load a resource bundle from a file that was not included in the JAR. Failure to load this resource produced reporting that lead me in the wrong direction:
Caused by: java.util.MissingResourceException: Can't find bundle for base name propFile, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
at com.foo.bar.MyApp(MyApp.java:103)
Could not find the main class: com.foo.bar.MyApp. Program will exit.
I'm developing on Win 7 64-bit with Eclipse Juno and JDK 1.6_45, both 32-bit. I'm generating an executable JAR with a mvn clean install invocation.
When I attempt to launch the app I've received "Could not find the main class" or "Failed to load Main-Class manifest attribute"
Similar ground has been covered here and here. I've read through these answers and the basic maven examples, but I'm still failing to end up
with an executable JAR.
I've attempted to execute the app with both java -jar MyApp-jar-with-dependencies and java -cp MyApp-jar-with-dependencies com.foo.bar.MyApp invocations
I find it particularly confusing that the MANIFEST.MF (contined within META-INF within the JAR) specifically lists my target main class, and the MyApp.class file is present in the directory tree at the correct location (com\foo\bar\MyApp.class).
I have refactored my package name and class name a few times over the course of development. Might this action have caused some referencing/classpath hiccup? Where else could the main class lookup failing?
My pom.xml:
<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>
<parent>
[...]
</parent>
<groupId>com.foo.bar</groupId>
<artifactId>MyApp</artifactId>
<packaging>jar</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<name>MY APP</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<issues-product>APP</issues-product>
<issues-component>MY_APP</issues-component>
</properties>
<dependencies>
[...]
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.version}</version>
<configuration>
[...]
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven.pmd.version}</version>
<configuration>
[...]
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.version}</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.foo.bar.MyApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
[...]
</pluginManagement>
</build>
<reporting>
[...]
</reporting>
<scm>
[...]
</scm>
</project>
My MANIFEST.MF within the the output JAR:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: myname
Build-Jdk: 1.6.0_45
Main-Class: com.foo.bar.MyApp
I'm not sure why yours isn't working, here is a cut-n-paste from my working maven project. You should only have to replace com.pictureu.mains.MainGui with your main class to test
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.pictureu.mains.MainGui</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

Categories