I am trying to call Twilio SMS API to trigger SMS using my java code. I am using twilio provided supporting library. All looks fine when I run the code in IDE however I am getting below error when convert into Jar and run it by passing the parameter
Exception in thread "main" java.lang.NoClassDefFoundError:
com/twilio/Twilio
at twilioSMS.TwilioSmsMsging.main(TwilioSmsMsging.java:15) Caused by: java.lang.ClassNotFoundException: com.twilio.Twilio
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)
... 1 more
Below is my code
package twilioSMS;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
public class TwilioSmsMsging {
public static void main(String[] args) {
String ACCOUNT_SID = args[0];
String AUTH_TOKEN = args[1];
String toMobileNumber = args[2];
String fromMobileNumber = args[3];
String smsMessage = args[4];
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(new com.twilio.type.PhoneNumber(toMobileNumber),new com.twilio.type.PhoneNumber(fromMobileNumber),smsMessage).create();
System.out.println(message.getSid());
}
}
My bad.. I have to export as runnable jar however I have exported as jar. Now issue resolved after exporting as runnable jar.
Related
I have created a maven project and writing tests in it using testng. I have also created an executable jar using maven but getting error when executing the jar in command prompt with the arguments that are used in project. I could not actually figure out the error. Please help me with this.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: org/testng/TestNG
at mypackage.App.main(App.java:40)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
command prompt error image in this link
My project Main class codes(App.java)
public class App {
public static String testdataExcel;
public static Properties props = null;
public static Properties loadPropertyFile(String filepath) throws IOException {
FileInputStream stream = new FileInputStream(filepath);
props = new Properties();
props.load(stream);
return props;
}
public static void main(String[] args) throws IOException, InterruptedException {
//Receiving arguments from command prompt
String Filename = args[0];
testdataExcel = args[1];
loadPropertyFile(Filename);
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { LoginPage.class, testclass2.class,
testclass3.class, testclass4.class,
testclass5.class, testclass6.class });
testng.run();
}
}
I have tried to reinstall java, testng as well and then i ran the project but i am getting same error. i could not figure out actual error so far. so kindly help me to find the error and complete this task.
Thanks in advance :)
I have been doing this tutorial.
But I cant seem to get the app running. After hours of trying to fix the errors, I have pinpointed it to this line in my MainActivity.Java SCService scService = SoundCloud.getService(); (just to point out I am a bit inexperienced when it comes to Java errors).
So I decided to create a little program to test whether the API calls is retrieving and anything(I'm trying to get the track from my soundcloud account)
import retrofit.Call;
import retrofit.Retrofit;
import retrofit.http.GET;
public class MyTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.soundcloud.com/").build();
SCService service = retrofit.create(SCService.class);
System.out.println("Welcome boi");
System.out.println(service.me().toString());
}
public interface SCService {
#GET("tracks?client_id=" + Config.CLIENT_ID)
Callme();
}
}
And I'm getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: okio/Source
at retrofit.Retrofit$Builder.baseUrl(Retrofit.java:301)
at com.casula.testingapp.MyTest.main(MyTest.java:12)
Caused by: java.lang.ClassNotFoundException: okio.Source
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
Please help I think it has something to do with my Retrofit.jar library. I'm using Retrofit2.0.0-3beta and Eclipse IDE - How do I fix this to be able to retrieve the track from my account?
I'm wanting to read an iCalendar (ics file) for a project and thinking it might be easier to just use an API. After much research I found iCal4j.
I'm new to ical4j, and have been searching for an answer, and trying to do research and found that the creator of it allows any form of logging they want, so I'm really baffled. I'm trying to get just a simple example I found working. I'm horrible with different APIs, and it kills me. I just have the iCal4j-2.0-beta1.jar in my classpath, and I have the following code:
import java.io.*;
import net.fortuna.ical4j.data.*;
import net.fortuna.ical4j.model.*;
public class iCalendarSupport
{
public static void main(String[] args)
{
try
{
FileInputStream fin = new FileInputStream("C:\\Users\\Mike\\Downloads\\basic (1).ics");
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(fin);
System.out.println(calendar.getComponent("Event").toString());
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Here's the output I have in the console in eclipse.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at net.fortuna.ical4j.util.Configurator.<clinit>(Configurator.java:51)
at net.fortuna.ical4j.data.CalendarParserFactory.<clinit>(CalendarParserFactory.java:63)
at net.fortuna.ical4j.data.CalendarBuilder.<init>(CalendarBuilder.java:104)
at iCalendarSupport.main(iCalendarSupport.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 4 more
Any help would be much appreciated.
Classpath is missing the SLF4J (Simple Logging Facade) library. You can find it here:
http://www.slf4j.org/download.html
At the beginning I had an error java.lang.ClassNotFoundException. I solved this problem by adding jars to \war\WEB-INF\lib folder. But then I got java.lang.NoClassDefFoundError: Could not initialize class com.orientechnologies.orient.core.Orient error while applying to database. This is the server code:
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public String greetServer(String input) throws IllegalArgumentException {
RegBugs rb = new RegBugs();
String a = rb.getDbAdres();
try {
//The error is here
ArrayList<String> table = rb.getAllGitRecords();
} catch (ParseException e) {
e.printStackTrace();
}
return a;
}
Compilation is finished successfully. And when I start to call to server I get An error occurred while attempting to contact the server. Please check your network connection and try again. from gwt. How could I solve this problem?
P.S. I use eclipse and gwt-plugin for it
The error occurs when I try to interrupt with orient database.
Trace:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.orientechnologies.orient.core.Orient
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.open(ODatabaseRaw.java:108)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:53)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:127)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:53)
at ru.sersem.testgwt.server.RegBugs.getBugRecordsCount(RegBugs.java:192)
at ru.sersem.testgwt.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 40 more
All,
The following code works fine and sends email when ran from within eclipse. However when i export from eclipse as a jar file and run the following command from a batch file it gives me error. Note: there are other files in the jar file that work fine when ran from the batch file.
java -cp C:\Users\Administrator\Email.jar LotusNotes.SendEmail
Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
xception
at LotusNotes.RunBackUpSourceCopy.main(RunBackUpSourceCopy.java:49)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unknown Source)
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)
SendEmail class:
public class SendEmail {
public String to ;
public String from;
public String host;
public SendEmail(){
to = "xyz#gmail.com";
from = "localhost";
host = "localhost";}
public void send_production_email(String reportDate){
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Subject Line!");
message.setText("Test email!");
Transport.send(message);
System.out.println("Sent message successfully....");
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("Preparing to Send Email ...");
SendEmail email = new SendEmail();
email.send_production_email("test production");
}
}
Looks you need to add javax mail jar to your class path.
Edit
java -cp "C:\Users\Administrator\Email.jar";"C:\Users\Administrator\ExternalJarFiles\mail.jar"; LotusNotes.SendEmail
Based on the comment bellow...