java - Understanding of the classpath and the classloader -


the root of misunderstanding concerns classpath or classloader me i'll depict in context first steps openejb.

i playing openejb embedded , faced strange issues. using maven pull dependencies , 1 of jar containing ejbs.

my application creates ejb container , try lookup 1 of @singleton contained in dependencies.

case 1)

when i'm launching main netbeans, relies on maven (exec-maven-plugin) working fine, can lookup bean. uses command line :

mvn -e "-dexec.args=-classpath %classpath com.app.main" -dexec.executable=/usr/lib/jvm/java-7-openjdk/bin/java org.codehaus.mojo:exec-maven-plugin:1.2.1:exec

case 2)

if try package application jar dependencies in specific folder lib ejbs not found.

here part of pom.xml create manifest.mf , put dependencies in lib folder.

<plugin>     <groupid>org.apache.maven.plugins</groupid>     <artifactid>maven-jar-plugin</artifactid>     <version>2.4</version>     <configuration>         <archive>             <index>true</index>             <manifest>                 <classpathprefix>./lib/</classpathprefix>                 <addclasspath>true</addclasspath>                 <mainclass>com.app.main</mainclass>             </manifest>         </archive>     </configuration> </plugin> 

i'm running application way : java -jar target/app.jar

now i'm wondering why in case 1 can find ejb's , not in case 2.

i added piece of code :

    classloader cl = classloader.getsystemclassloader();      url[] urls = ((urlclassloader)cl).geturls();      (url url: urls){         system.out.println(url.getfile());     } 

which shows me in case 1 dependencies current jar in case 2

when opening manifest.mf generated jar dependencies correctly appended class-path.

can clarify me ?


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -