You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Chris24300 <ch...@hotmail.com> on 2011/04/20 13:54:28 UTC

Packaged jar cannot access class of a dependency??

Hi all,

I'm trying to test out db4o (new to db in general) and so I created a new
project to test dumping some random data in.  I use three classes

import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.cs.Db4oClientServer;

In my pom.xml I include the db4o repository and the dependency, I wasn't
able to connect to the repository at one point so I installed it to my local
repo and everything was building.. When I goto run the jar I get an class
not found exception with Db4oClientServer, I searched threw the db4o jar and
the class is in there...

Here's the error:
bash-3.2$ java -jar Db4oServer.jar 
Running server test...
Exception in thread "main" java.lang.NoClassDefFoundError:
com/db4o/cs/Db4oClientServer
        at myTest.db4o.client.TestClient.test(TestClient.java:32)
        at myTest.db4o.client.TestClient.main(TestClient.java:22)
Caused by: java.lang.ClassNotFoundException: com.db4o.cs.Db4oClientServer
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 2 more

I don't know what I messed up but it doesn't like something.  When I search
through the jar maven packaged I only see my classes, is the db4o jar
supposed to be included as well? Can someone help me out?

Thanks!


--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315587.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Chris24300 <ch...@hotmail.com>.
I added a <addClasspath> tag and it included the classpath in the manifest, I
thought I was getting somewhere but still get the same error..

I ended up using a new eclipse project and copying my stuff over and
exporting as exec jar and it works... 

--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4328511.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Chris24300 <ch...@hotmail.com>.
Thanks for the link, I'll look into it.  I want to create a library that will
handle everything for me so I can pass it an Object to store, I need to test
the client first to make sure it can store..

--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4328333.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Timothy Mcginnis <tm...@aessuccess.org>.
Are you expecting this to run as part of the default packaging phase?

If so, I believe you are missing an <executions> section for the assembly 
plugin that binds the 'single' goal to the packaging phase.

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.1</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </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>
      [...]
</project>


See the "Execution: Building An Assembly" section of this page 
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html


Tim McGinnis
717 720-1962
Web Development
AES/PHEAA



From:
Chris24300 <ch...@hotmail.com>
To:
users@maven.apache.org
Date:
04/20/2011 08:25 AM
Subject:
Re: Packaged jar cannot access class of a dependency??



Thanks for replying with the link, I've already included the main class in 
my
pom

Majority of my pom

<build>
                                 <finalName>Db4oServer</finalName>

                                 <plugins>
                                                 <plugin>
 <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
  <source>1.5</source>
  <target>1.5</target>
 </configuration>
                                                 </plugin>

                                                 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
 <configuration>
  <archive>
                 <manifest>
  <mainClass>${groupId}.TestClient</mainClass>
                                 <packageName>${groupId}</packageName>
                 </manifest>
                 <manifestEntries>
                                 <mode>development</mode>
                                 <url>${pom.url}</url>
                 </manifestEntries>
  </archive>
 </configuration>
                                                 </plugin>
                                                 <plugin>
 <artifactId>maven-assembly-plugin</artifactId>
 <configuration>
  <archive>
                 <manifest>
  <mainClass>${groupId}.TestClient</mainClass>
                 </manifest>
  </archive>
  <descriptorRefs>
                 <descriptorRef>jar-with-dependencies</descriptorRef>
  </descriptorRefs>
 </configuration>
                                                 </plugin>

                                 </plugins>
                 </build>

--
View this message in context: 
http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315651.html

Sent from the Maven - Users mailing list archive at Nabble.com.

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





==============================================================================
This message contains privileged and confidential information intended for the above addressees only.  If you
receive this message in error please delete or destroy this message and/or attachments.  

The sender of this message will fully cooperate in the civil and criminal prosecution of any individual engaging
in the unauthorized use of this message.
==============================================================================

Re: Packaged jar cannot access class of a dependency??

Posted by Chris24300 <ch...@hotmail.com>.
What confuses me is that it doesn't complain about the other two classes,
ObjectContainer and ObjectSet....?

--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315664.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Chris24300 <ch...@hotmail.com>.
Thanks for replying with the link, I've already included the main class in my
pom

Majority of my pom

<build>
		<finalName>Db4oServer</finalName>

		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.5</source>
					<target>1.5</target>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>${groupId}.TestClient</mainClass>
							<packageName>${groupId}</packageName>
						</manifest>
						<manifestEntries>
							<mode>development</mode>
							<url>${pom.url}</url>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>${groupId}.TestClient</mainClass>
						</manifest>
					</archive>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
				</configuration>
			</plugin>

		</plugins>
	</build>

--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315651.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Thomas Sundberg <ts...@kth.se>.
On Wed, Apr 20, 2011 at 14:12, Chris24300 <ch...@hotmail.com> wrote:
> I thought maven would include the db4o jar in my project jar?
>
> If I specify -classpath and point to db4o.jar then java can't find my test
> class.
>
> bash-3.2$ java -classpath ./db4o-8.0.184.15484-all-java5.jar -jar
> Db4oServer.jar
>
> Does not even run..

If you want an executable jar, then you have to specify a main class
and make sure that what you need is included. I wrote a little about a
while ago. You can read it at

http://thomassundberg.wordpress.com/2011/03/05/create-an-executable-jar-from-maven/

HTH
Thomas

>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315628.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

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


Re: Packaged jar cannot access class of a dependency??

Posted by Chris24300 <ch...@hotmail.com>.
I thought maven would include the db4o jar in my project jar? 

If I specify -classpath and point to db4o.jar then java can't find my test
class.  

bash-3.2$ java -classpath ./db4o-8.0.184.15484-all-java5.jar -jar
Db4oServer.jar 

Does not even run..

--
View this message in context: http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315628.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Packaged jar cannot access class of a dependency??

Posted by Anders Hammar <an...@hammar.net>.
But you're not including the jb4o jar in the classpath when you're
executing?
As you're executing your Java program the standard Java way Maven is not
involved.

/Anders

On Wed, Apr 20, 2011 at 13:54, Chris24300 <ch...@hotmail.com> wrote:

> Hi all,
>
> I'm trying to test out db4o (new to db in general) and so I created a new
> project to test dumping some random data in.  I use three classes
>
> import com.db4o.ObjectContainer;
> import com.db4o.ObjectSet;
> import com.db4o.cs.Db4oClientServer;
>
> In my pom.xml I include the db4o repository and the dependency, I wasn't
> able to connect to the repository at one point so I installed it to my
> local
> repo and everything was building.. When I goto run the jar I get an class
> not found exception with Db4oClientServer, I searched threw the db4o jar
> and
> the class is in there...
>
> Here's the error:
> bash-3.2$ java -jar Db4oServer.jar
> Running server test...
> Exception in thread "main" java.lang.NoClassDefFoundError:
> com/db4o/cs/Db4oClientServer
>        at myTest.db4o.client.TestClient.test(TestClient.java:32)
>        at myTest.db4o.client.TestClient.main(TestClient.java:22)
> Caused by: java.lang.ClassNotFoundException: com.db4o.cs.Db4oClientServer
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        ... 2 more
>
> I don't know what I messed up but it doesn't like something.  When I search
> through the jar maven packaged I only see my classes, is the db4o jar
> supposed to be included as well? Can someone help me out?
>
> Thanks!
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Packaged-jar-cannot-access-class-of-a-dependency-tp4315587p4315587.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>