You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Matthias Hofmann <ma...@tu-dortmund.de> on 2010/03/08 15:03:07 UTC

Problems with Dependencies and Classpath

Hi,

currently i am trying to get my Java program running outside of the
Netbeans IDE. Within Netbeans, it works well, all dependencies are
correctly loaded and executed.
But if i try to run the program from the console with java -cp or java
-jar, i get NoClassFoundDefError concerning the dependencies of the
project.

My pom.xml uses

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>...omitted...</mainClass>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

as buildoptions

Any ideas concerning this issue? Most likely, sth. with the classpath is
wrong, but i can't figure it out.

Best regards and thank you,

Matthias



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problems with Dependencies and Classpath

Posted by Matthias Hofmann <ma...@tu-dortmund.de>.
Hello,

tank you for the fast and many replies!!
works fine now.
Maybe it would be useful to integrate this issue in the maven "Getting
started" documentation.

Best regards,

Matthias

> Le Mon, 8 Mar 2010 15:03:07 +0100,
> "Matthias Hofmann" <ma...@tu-dortmund.de> a écrit :
>
>> Hi,
>>
>> currently i am trying to get my Java program running outside of the
>> Netbeans IDE. Within Netbeans, it works well, all dependencies are
>> correctly loaded and executed.
>> But if i try to run the program from the console with java -cp or java
>> -jar, i get NoClassFoundDefError concerning the dependencies of the
>> project.
>>
> - Use the plugin dependencies to obtain all required jar (for example put
> it in target/lib)
>
> <plugin>
>                 <artifactId>maven-dependency-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <goals>
>                             <goal>copy-dependencies</goal>
>                         </goals>
>                         <configuration>
>                             <outputDirectory>${project.build.directory}/lib</outputDirectory>
>                         </configuration>
>                     </execution>
>                 </executions>
> </plugin>
>
> - then in jar plugin tells it to use your prefix
>
> <plugin>
>                     <artifactId>maven-jar-plugin</artifactId>
>                     <configuration>
>                         <archive>
>                             <manifest>
>                                 <mainClass>...omitted...</mainClass>
>                                 <addClasspath>true</addClasspath>
>                                 <classpathPrefix>./lib/</classpathPrefix>
>                             </manifest>
>                         </archive>
>                     </configuration>
> </plugin>
>
> Then you can launch your application via java -jar tar/XXX.jar
>
> Works fine for us :) hope it will help you.
>
>
>> My pom.xml uses
>>
>> <plugin>
>>                 <groupId>org.apache.maven.plugins</groupId>
>>                 <artifactId>maven-jar-plugin</artifactId>
>>                 <configuration>
>>                     <archive>
>>                         <manifest>
>>                             <mainClass>...omitted...</mainClass>
>>                             <addClasspath>true</addClasspath>
>>                         </manifest>
>>                     </archive>
>>                 </configuration>
>>             </plugin>
>>
>> as buildoptions
>>
>> Any ideas concerning this issue? Most likely, sth. with the classpath is
>> wrong, but i can't figure it out.
>>
>> Best regards and thank you,
>>
>> Matthias
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>
>
>
> --
>
> Tony Chemit
> --------------------
> tél: +33 (0) 2 40 50 29 28
> email: chemit@codelutin.com
> http://www.codelutin.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problems with Dependencies and Classpath

Posted by Tony Chemit <ch...@codelutin.com>.
Le Mon, 8 Mar 2010 15:03:07 +0100,
"Matthias Hofmann" <ma...@tu-dortmund.de> a écrit :

> Hi,
> 
> currently i am trying to get my Java program running outside of the
> Netbeans IDE. Within Netbeans, it works well, all dependencies are
> correctly loaded and executed.
> But if i try to run the program from the console with java -cp or java
> -jar, i get NoClassFoundDefError concerning the dependencies of the
> project.
> 
- Use the plugin dependencies to obtain all required jar (for example put it in target/lib)

<plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
</plugin>

- then in jar plugin tells it to use your prefix

<plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>...omitted...</mainClass>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>./lib/</classpathPrefix>
                            </manifest>
                        </archive>
                    </configuration>
</plugin>

Then you can launch your application via java -jar tar/XXX.jar

Works fine for us :) hope it will help you.


> My pom.xml uses
> 
> <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-jar-plugin</artifactId>
>                 <configuration>
>                     <archive>
>                         <manifest>
>                             <mainClass>...omitted...</mainClass>
>                             <addClasspath>true</addClasspath>
>                         </manifest>
>                     </archive>
>                 </configuration>
>             </plugin>
> 
> as buildoptions
> 
> Any ideas concerning this issue? Most likely, sth. with the classpath is
> wrong, but i can't figure it out.
> 
> Best regards and thank you,
> 
> Matthias
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 



-- 

Tony Chemit
--------------------
tél: +33 (0) 2 40 50 29 28
email: chemit@codelutin.com  
http://www.codelutin.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problems with Dependencies and Classpath

Posted by Shanbo Li <sh...@gmail.com>.
Hello Matthias,

Read this:
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

You can use
mvn assembly:assembly
To get a jar with all dependencies.

BR,
Shanbo


On Mon, Mar 8, 2010 at 10:10 PM, Milos Kleint <mk...@gmail.com> wrote:

> On Mon, Mar 8, 2010 at 3:03 PM, Matthias Hofmann <
> matthias.hofmann@tu-dortmund.de> wrote:
>
> > Hi,
> >
> > currently i am trying to get my Java program running outside of the
> > Netbeans IDE. Within Netbeans, it works well, all dependencies are
> > correctly loaded and executed.
> > But if i try to run the program from the console with java -cp or java
> > -jar, i get NoClassFoundDefError concerning the dependencies of the
> > project.
> >
> > My pom.xml uses
> >
> > <plugin>
> >                <groupId>org.apache.maven.plugins</groupId>
> >                <artifactId>maven-jar-plugin</artifactId>
> >                <configuration>
> >                    <archive>
> >                        <manifest>
> >                            <mainClass>...omitted...</mainClass>
> >                            <addClasspath>true</addClasspath>
> >
>
> this willl just generate the relevant manifest entry, but will not ensure
> that the jars are at the designated location at runtime. To get them there,
> you could use the maven-assembly plugin, or you could merge all dependency
> jars into the main jar using the maven-shade-plugin.
>
> Milos
>
>
> >                        </manifest>
> >                    </archive>
> >                </configuration>
> >            </plugin>
> >
> > as buildoptions
> >
> > Any ideas concerning this issue? Most likely, sth. with the classpath is
> > wrong, but i can't figure it out.
> >
> > Best regards and thank you,
> >
> > Matthias
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>



-- 
Shanbo Li

Master student
Software Engineering of Distributed Systems, KTH

Re: Problems with Dependencies and Classpath

Posted by Milos Kleint <mk...@gmail.com>.
On Mon, Mar 8, 2010 at 3:03 PM, Matthias Hofmann <
matthias.hofmann@tu-dortmund.de> wrote:

> Hi,
>
> currently i am trying to get my Java program running outside of the
> Netbeans IDE. Within Netbeans, it works well, all dependencies are
> correctly loaded and executed.
> But if i try to run the program from the console with java -cp or java
> -jar, i get NoClassFoundDefError concerning the dependencies of the
> project.
>
> My pom.xml uses
>
> <plugin>
>                <groupId>org.apache.maven.plugins</groupId>
>                <artifactId>maven-jar-plugin</artifactId>
>                <configuration>
>                    <archive>
>                        <manifest>
>                            <mainClass>...omitted...</mainClass>
>                            <addClasspath>true</addClasspath>
>

this willl just generate the relevant manifest entry, but will not ensure
that the jars are at the designated location at runtime. To get them there,
you could use the maven-assembly plugin, or you could merge all dependency
jars into the main jar using the maven-shade-plugin.

Milos


>                        </manifest>
>                    </archive>
>                </configuration>
>            </plugin>
>
> as buildoptions
>
> Any ideas concerning this issue? Most likely, sth. with the classpath is
> wrong, but i can't figure it out.
>
> Best regards and thank you,
>
> Matthias
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>