You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mi...@faa.gov on 2015/08/03 22:45:02 UTC
Problem Executing A Mavan Built Program
I created the source code for a very simple Java program in Eclipse.
Then I ran mvn install to build the program, which worked fine.
The following are the errors I am getting when I try to run the program built by Maven from the command line. I have included the command prompt errors; the source code and the POM file. I have also searched extensively for both of the execution time errors I am encountering but have been unable to find any explanation that works, and I've tried several.
Attempt(s) to execute the class file:
H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java SimpleNoLibraryProgram
Error: Could not find or load main class SimpleNoLibraryProgram
H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java main.java..org.prog.SimpleNoLibraryProgram
Error: Could not find or load main class main.java..org.prog.SimpleNoLibraryProgram
Attempt to execute the JAR file:
C:\Users\Michael CTR Tarullo.FAA\.m2\program-build-repository\main\java\org\prog\SimpleNoLibraryProgram\1.0>java -jar SimpleNoLibraryProgram-1.0.jar
no main manifest attribute, in SimpleNoLibraryProgram-1.0.jar
Source code:
package main.java.org.prog;
public class SimpleNoLibraryProgram
{
public static void main(String[] args)
{
System.out.println("Hello Simple No Library Program!!!");
}
}
POM file:
<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>main.java.org.prog</groupId>
<artifactId>SimpleNoLibraryProgram</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>SimpleNoLibraryProgram</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Michael Tarullo
Contractor (Engility Corp)
Enterprise Architect
NSRR System Administrator
FAA WJH Technical Center
(609)485-5294
Re: Problem Executing A Mavan Built Program
Posted by Brice Vandeputte <bv...@gmail.com>.
Michael,
another way is to render your jar file "executable" by adding mainClass
entry to your jar manifest file
then you will be able to launch your application using
java -jar yours.jar
have a look at
https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make
-- setup a maven jar build plugin into your pom
-- configure main class four your generated archive
regards
2015-08-04 10:26 GMT+02:00 Adrien Rivard <ad...@gmail.com>:
> Hi,
>
> Your packages/directories are not correct:
>
> That should work :
> H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes>
> java
> main.java.org.prog.SimpleNoLibraryProgram
> Error: Could not find or load main class
> main.java..org.prog.SimpleNoLibraryProgram
>
> But "main/java" is not supposed to be part of the package name
>
> structure of your project should be
> - [projectDir]/src/main/java/org/prog/SimpleNoLibraryProgram
> - [projectDir]/pom.xml
>
> package of SimpleNoLibraryProgram.java is supposed to be only
> org.prog.SimpleNoLibraryProgram
>
> then you can run mvn package in project dir, and run "java
> org.prog.SimpleNoLibraryProgram" in [projectDir]/target/classes
>
> Note that invoking java on a maven project ike this is only doable for very
> simple projects without dependencies.
>
>
> On Mon, Aug 3, 2015 at 10:45 PM, <Mi...@faa.gov> wrote:
>
> > I created the source code for a very simple Java program in Eclipse.
> >
> > Then I ran mvn install to build the program, which worked fine.
> >
> > The following are the errors I am getting when I try to run the program
> > built by Maven from the command line. I have included the command prompt
> > errors; the source code and the POM file. I have also searched
> extensively
> > for both of the execution time errors I am encountering but have been
> > unable to find any explanation that works, and I've tried several.
> >
> > Attempt(s) to execute the class file:
> >
> H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java
> > SimpleNoLibraryProgram
> > Error: Could not find or load main class SimpleNoLibraryProgram
> >
> >
> H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java
> > main.java..org.prog.SimpleNoLibraryProgram
> > Error: Could not find or load main class
> > main.java..org.prog.SimpleNoLibraryProgram
> >
> >
> >
> > Attempt to execute the JAR file:
> > C:\Users\Michael CTR
> >
> Tarullo.FAA\.m2\program-build-repository\main\java\org\prog\SimpleNoLibraryProgram\1.0>
> > no main manifest attribute, in SimpleNoLibraryProgram-1.0.jar
> >
> >
> > Source code:
> > package main.java.org.prog;
> >
> > public class SimpleNoLibraryProgram
> > {
> > public static void main(String[] args)
> > {
> > System.out.println("Hello Simple No
> > Library Program!!!");
> > }
> > }
> >
> >
> >
> > POM file:
> > <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>main.java.org.prog</groupId>
> > <artifactId>SimpleNoLibraryProgram</artifactId>
> > <version>1.0</version>
> > <packaging>jar</packaging>
> >
> > <name>SimpleNoLibraryProgram</name>
> > <url>http://maven.apache.org</url>
> >
> > <properties>
> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> > </properties>
> >
> > <dependencies>
> > <dependency>
> > <groupId>junit</groupId>
> > <artifactId>junit</artifactId>
> > <version>3.8.1</version>
> > <scope>test</scope>
> > </dependency>
> > </dependencies>
> > </project>
> >
> > Michael Tarullo
> > Contractor (Engility Corp)
> > Enterprise Architect
> > NSRR System Administrator
> > FAA WJH Technical Center
> > (609)485-5294
> >
> >
>
>
> --
> Adrien Rivard
>
Re: Problem Executing A Mavan Built Program
Posted by Adrien Rivard <ad...@gmail.com>.
Hi,
Your packages/directories are not correct:
That should work :
H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes> java
main.java.org.prog.SimpleNoLibraryProgram
Error: Could not find or load main class
main.java..org.prog.SimpleNoLibraryProgram
But "main/java" is not supposed to be part of the package name
structure of your project should be
- [projectDir]/src/main/java/org/prog/SimpleNoLibraryProgram
- [projectDir]/pom.xml
package of SimpleNoLibraryProgram.java is supposed to be only
org.prog.SimpleNoLibraryProgram
then you can run mvn package in project dir, and run "java
org.prog.SimpleNoLibraryProgram" in [projectDir]/target/classes
Note that invoking java on a maven project ike this is only doable for very
simple projects without dependencies.
On Mon, Aug 3, 2015 at 10:45 PM, <Mi...@faa.gov> wrote:
> I created the source code for a very simple Java program in Eclipse.
>
> Then I ran mvn install to build the program, which worked fine.
>
> The following are the errors I am getting when I try to run the program
> built by Maven from the command line. I have included the command prompt
> errors; the source code and the POM file. I have also searched extensively
> for both of the execution time errors I am encountering but have been
> unable to find any explanation that works, and I've tried several.
>
> Attempt(s) to execute the class file:
> H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java
> SimpleNoLibraryProgram
> Error: Could not find or load main class SimpleNoLibraryProgram
>
> H:\EclipseWorkspacesLunaForMaven\SimpleNoLibraryProject\target\classes\main\java\org\prog>java
> main.java..org.prog.SimpleNoLibraryProgram
> Error: Could not find or load main class
> main.java..org.prog.SimpleNoLibraryProgram
>
>
>
> Attempt to execute the JAR file:
> C:\Users\Michael CTR
> Tarullo.FAA\.m2\program-build-repository\main\java\org\prog\SimpleNoLibraryProgram\1.0>
> no main manifest attribute, in SimpleNoLibraryProgram-1.0.jar
>
>
> Source code:
> package main.java.org.prog;
>
> public class SimpleNoLibraryProgram
> {
> public static void main(String[] args)
> {
> System.out.println("Hello Simple No
> Library Program!!!");
> }
> }
>
>
>
> POM file:
> <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>main.java.org.prog</groupId>
> <artifactId>SimpleNoLibraryProgram</artifactId>
> <version>1.0</version>
> <packaging>jar</packaging>
>
> <name>SimpleNoLibraryProgram</name>
> <url>http://maven.apache.org</url>
>
> <properties>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> </properties>
>
> <dependencies>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>3.8.1</version>
> <scope>test</scope>
> </dependency>
> </dependencies>
> </project>
>
> Michael Tarullo
> Contractor (Engility Corp)
> Enterprise Architect
> NSRR System Administrator
> FAA WJH Technical Center
> (609)485-5294
>
>
--
Adrien Rivard