I wrote a simple java program that will require external jar file to compile and run. I've successfully compiled the .java file but i keep getting "Error: could not find or load main class 'Simple' " whenever i try to run the .class file using java command
            Asked
            
        
        
            Active
            
        
            Viewed 40 times
        
    -2
            
            
        - 
                    3show your code and how you call it. Also read [ask]. – Jens Dec 22 '16 at 11:02
- 
                    Provide the code and error you are getting. – Tilak Raj Dec 22 '16 at 11:09
- 
                    Might be you forget to set path. – Tilak Raj Dec 22 '16 at 11:10
- 
                    Well... you want us to debug your code, but you don't show it... – aschipfl Dec 22 '16 at 13:11
3 Answers
1
            You are missing your class itself in classpath, use . while running your code
On windows:
java -classpath external.jar;. MyClass
On linux:
java -classpath external.jar:. MyClass
0
            
            
        You can use the -classpath argument of javac.
javac -classpath path/to/library1.jar MyClass.java
 
    
    
        screab
        
- 169
- 3
- 14
- 
                    Yeah, I've compiled it with such command but here is the command i used to run it "java -classpath external.jar MyClass" – Ismail Dec 22 '16 at 11:10
- 
                    
- 
                    Also, I think you need to put .java after MyClass. Try "javac -classpath external.jar MyClass.java" – screab Dec 22 '16 at 11:13
- 
                    I did it and it compiles successfully using the command you provided. It generated a .class file as expected – Ismail Dec 22 '16 at 11:14
 
    