I developp a web app in eclipse with spring to handle dependency injection & maven to deploy. I'm trying to make work this little code :
public class MainExternal {
public static void main( String[] args ) throws Exception{
        @SuppressWarnings("resource")           ApplicationContext appContext = new ClassPathXmlApplicationContext( "classpath*:webConfiguration/applicationContext.xml");          ProjectBo projectBo                  = (ProjectBo) appContext.getBean("projectBo");
        System.out.println("-> Im 'in ");
        /************* PRINT OUT  *************/
        Project project = projectBo.findByNameOfStudy("Profiler");
        List<User> listUser = (List<User>) projectBo.findUsers(project);
        for (User myUser : listUser) {
                        System.out.println("User :"+myUser.getFirstname());
        }   
}
When i run it inside eclipse, it works.
But when i call it from my web app like followed, it doesn't work :
public void throwAnalyse(){
    System.out.println("->I call my function");
    try {
    String[] command= {"java","-cp", "/Users/JP/git/CleanOmicsTracer/target/CleanOmicsTracer.jar", "com.clb.genomic.lyon.external.MainExternal"};
    Process p = Runtime.getRuntime().exec(command);
    ////////////////////////////////////////////
    //test for remote command
    String line;
    BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            while ((line = bri.readLine()) != null) {
                System.out.println(line);
            }
            bri.close();
            while ((line = bre.readLine()) != null) {
                System.out.println(line);
            }
            bre.close();
     p.waitFor();
    } catch (IOException e) {  e.printStackTrace();
    } catch (InterruptedException e) {  e.printStackTrace(); }
    System.out.println("End of programme");
}
When i tried to execute from console as :
java -cp /Users/JP/git/CleanOmicsTracer/target/CleanOmicsTracer.jar com.clb.genomic.lyon.external.MainExternal
It doesn't work anymore and throws :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext 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:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 
    