Solved

Running jar file from command prompt

Posted on 2010-09-03
15
796 Views
Last Modified: 2012-05-10
When i run my program from netbeans, everything works well. But when i try to run it from the command prompt using java -jar JavaApplication3.jar i get the following errors:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/logging/
LogDomains
        at com.sun.appserv.security.ProgrammaticLogin.<clinit>(Programmatic
Login.java:85)
        at demo.Main.main(Main.java:31)
Caused by: java.lang.ClassNotFoundException: com.sun.logging.LogDomains
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

What do i need to do to make it run from commandline?
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo;

import com.sun.appserv.security.ProgrammaticLogin;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

/**
 *
 * @author js
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Hashtable env = new Hashtable();
        env.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
        env.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
        env.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
        //env.put("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
        env.put("org.omg.CORBA.ORBInitialHost", "10.10.22.106");
        env.put("org.omg.CORBA.ORBInitialPort", "3700");

        ProgrammaticLogin pm = new ProgrammaticLogin();
        String user = "dummy";
        pm.login(user, "dummy"); //user and password of a user mapped to admin role

        

        InitialContext ctx;
        try {
            
            ctx = new InitialContext(env);

            javax.swing.JOptionPane.showMessageDialog(null, "Attempting to lookup");
            Object ref = ctx.lookup("demo.SB3Remote");
            javax.swing.JOptionPane.showMessageDialog(null, "Ey looked up!");
            //Object ref = ctx.lookup("java:global/HelloBean/Login2-ejb");
                        
            SB3Remote calc = (SB3Remote) PortableRemoteObject.narrow(ref, SB3Remote.class);            
            javax.swing.JOptionPane.showMessageDialog(null, " " + calc.Hello(user));

        } catch (Exception ex) {
            ex.printStackTrace();
        }        
    }
}

Open in new window

0
Comment
Question by:endasil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33598002
you need to add the classpath to the following command
java -jar -cp <path of jar file with classes required in classpath> filename.jar

for reference
http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html

download the jar file from here
http://www.findjar.com/jar/javax/xml/jaxrpc-api/1.1/jaxrpc-api-1.1.jar.html?all=true
0
 
LVL 92

Expert Comment

by:objects
ID: 33601228
you need to either add the relative location of the dependent jars to your manifest

or specify them on the command line

 java -cp JavaApplication3.jar;a.jar;b.jar demo.Main
0
 
LVL 2

Expert Comment

by:karthi_bv
ID: 33602159
FInd program dependent jars and set the class path like below and run the program

set classpath=.;c:/yourjars

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:endasil
ID: 33602573
i tried setting the classpath to the dist/lib directory where netbeans copy the libs i add to the project, but no difference.  
0
 
LVL 2

Expert Comment

by:chataros
ID: 33602756
in the manifest file set the executable class
take a look at ANSWER:
1
http://www.captain.at/programming/java/executable-java-application.php
0
 

Accepted Solution

by:
endasil earned 0 total points
ID: 33603233
Found the problem, i needed to add the appserv-deployment-client.jar to the project. Strange that it worked from the ide without this.
0
 
LVL 92

Expert Comment

by:objects
ID: 33605268
So where is it find the classes now?
0
 

Author Comment

by:endasil
ID: 33606684
Under dist/lib  as earlier. And i have no idea how it could have worked earlier from netbeans when i did not have appserv-deployment-client.jar added. If i delete any other lib from the project it wont run, but it seem to run fine without that jar when starting from  netbeans. That is still a mystery for me.
0
 

Author Comment

by:endasil
ID: 33606975
Should also add that it was able to find libraries under the lib folder automatically, so setting class path was not an issue in this case. But thank you all For trying to help! Really appreciated.
0
 

Author Comment

by:endasil
ID: 33606995
Should also add that it was able to find libraries under the lib folder automatically, so setting class path was not an issue in this case. But thank you all For trying to help! Really appreciated.
0
 
LVL 92

Expert Comment

by:objects
ID: 33608177
Check the manifest in your jar file, sounds like the jar is specified in there
0
 
LVL 92

Expert Comment

by:objects
ID: 33608191
> Should also add that it was able to find libraries under the lib folder automatically

only jars in ext directories get found automatically :)
0
 

Author Comment

by:endasil
ID: 33609833
Ah right,  netbeans adds a manifest to the jar when building  that contains lib/ as a classpath. That explains how it finds the files i added there.  I can find out that by extracting the files in the jar file with jar -xf javaapplication3.jar. But if i remove the  appserv-deployment-client.jar in netbeans, do a rebuild the manifest in the jar file contains no reference to appserv-deployment-client.jar. But it is still able to run it from netbeans.

I searched under my application3 directory for additional .mf files but the only one that exisit is a manifest.mt under the .\build\ direcotry that contains contains:
"
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
"

So how does it find things from that jar when inside netbeans?
0
 
LVL 92

Expert Comment

by:objects
ID: 33609862
check your projects build path
0
 

Author Comment

by:endasil
ID: 33609906
Hmm, That should be the build directory under Application3 that i mentioned earlier? It only  contains an "empty" manifest.mf file and the .class files. No other manifest.

C:\Users\js\Documents\NetBeansProjects\JavaApplication3\build>dir /s /w
 Volume in drive C has no label.
 Volume Serial Number is 5E3A-BF8F

 Directory of C:\Users\js\Documents\NetBeansProjects\JavaApplication3\build


[.]                    [..]                   built-jar.properties
[classes]              [empty]                manifest.mf
               2 File(s)            185 bytes

 Directory of C:\Users\js\Documents\NetBeansProjects\JavaApplication3\build
\classes

[.]    [..]   [demo]
               0 File(s)              0 bytes

 Directory of C:\Users\js\Documents\NetBeansProjects\JavaApplication3\build
\classes\demo

[.]               [..]              Main.class        SB3Remote.class
               2 File(s)          2 408 bytes

 Directory of C:\Users\js\Documents\NetBeansProjects\JavaApplication3\build
\empty

[.]  [..]
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 60
Notify sent to other threads in Java 9 52
java mysql insert application 14 64
Session in java desktop 5 34
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question