Using Javamail and Gmail - api

I am looking for a way to send mail using Javamail and the GMAIL SMTP.
Here is a page which provides some code
I have never worked with Public Classes before and also the page suggests that:
To run this example, you need two dependency libraries – javaee.jar
and mail.jar, both are bundle in JavaEE SDK.
Can someone please help me set up this script so that I can bind it to an event such as, OnClick.
Also if wanted to pass variables into the class such as: To, From, Subject, Body, how could I do this?
Please advise....
Thanks

The jars must be in your classpath at compile and runtime for this to work, this is true of any JAVA library (.jar/.zip)
From a command line you would compile with something like
javac -classpath .;path to javaee.jar;path to mail.jar myclass.java
and at runtime
java -classpath .;path to javaee.jar;path to mail.jar myclass
In an eclipse project you would add the mail.jar and javaee.jar to the projects as libraries.
This is pretty basic Java stuff here, I really think you may need to go read up a bit more on this, you will be including libraries as every day java development. There are pleanty of places to find out the fundamentals of this.

Related

build.gradle.kts:10:28: Unresolved reference: settings

I have seen examples for using "by settings" delegation in build.gradle.kts scripts, but no matter what I have tried to do, Gradle complains that settings is an unresolved reference. If I change 'settings' to 'project', Gradle is happy. Has the use of 'by settings' been deprecated? I looked in the Gradle 6.4.1 manual and it shows this delegation. I've attached an image showing a simple Spring Boot app generated by Initializr with the only changes being the addition of the gradle.properties file and the delegation in the build.gradle.kts file. I'd really appreciate any hints about this issue... I know that I can use 'extra' properties or finding the property against the project object, but, frankly, this issue has annoyed me to the point that I need to know what is wrong! :P. Thank you for any help...
The project delegate is defined in the class ProjectDelegate. Your build script is evaluated against an instance of KotlinBuildScript which extends Project, so the delegate is available.
However, when settings.gradle is evaluated, projects aren't configured yet, so there's no instance of KotlinBuildScript. Instead, the script is evaluated against an instance of KotlinSettingsScript which extends Settings, which has the settings delegate. I don't think this delegate was ever available to project build scripts.
In both cases the delegate is provided by an extension function, because both Project and Settings are Java files part of the Gradle core API.
I hope that answers your question.

Coroutines working but IntelliJ shows errors

I am working on a project using kotlinjs for nodejs and I start to learn coroutines and integrate them into my code to say goodbye to the callback hell.
I managed to get coroutines working, my code can be compiled and executed, everything seems fine.
...except: The IDE still shows me errors. It seems to be confused by the additional libraries I added in order to get coroutines running.
I am currently fiddling around with the library dependencies, sometimes some errors go away, but then some code gets red which was okay before...
This is what I see:
Case 1:
Cannot access class 'kotlinx.coroutines.experimental.CoroutineContext'. Check your module classpath for missing or conflicting dependencies
Case 2:
Unresolved reference: JsModule
Modifier 'external' is not applicable to 'class'
You see, launch is recognized when I add the stdlib, but then the IDE complains with the other two errors.
Again, please note: In both cases, actual compilation is successful!
I am using IntelliJ 2018.1 with Kotlin Plugin 1.2.41.
Thanks to Alexander Chernikov at youtrack.jetbrains I could resolve my problem.
I cite his explanation:
The issue is that JavaScript libraries should be marked with special attribute to be recognized.
When they are imported from pom.xml or build.gradle, this mark is set, so the feature works.
In your project they are not marked.
At the moment, to correct the libs manually, please open .idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_js_1_2_41.xml and .idea/libraries/org_jetbrains_kotlinx_kotlinx_coroutines_core_js_0_22_5.xml.
In both files find type="repository" and replace it with type="kotlin.js".
Make sure IDEA sees the change. (You can exit IDEA, make the change and restart.)
Then you can keep only these two libs in dependencies. The editor should work.
Here is the issue link:
https://youtrack.jetbrains.com/issue/KT-24575
There I have also attached a sample project with the problem.

Restlet : Requested resource not found

I am new to rest, so I followed this tutorial exactly the way its mentioned here:
However, I get a requested resource not found error when I hit the URI mentioned there, that is,
http://localhost:8080/RestletDemo/service/helloWorld
My build was successful.
This is the first time I am posting a question, my apologies for any ambiguity. Do let me know if you need more information.
It's difficult to figure out your problem like that. I have a look at your link and the problem of the provided code is that there are a lot of plumbing. Things could be much more simpler leveraging for example bean converters (Jackson one for example).
However, I didn't see anything strange in this code. Perhaps it's a configuration problem within your servlet container. For example, when using Tomcat with WTP in Eclipse, I need to check the item "Publish module contexts to separate XML files" to make things work.
I just submitted a very simple Restlet project targetting servlet and without all these plumbing. I made it work under Eclipse with WTP 2 (Tomcat7). You can reach it here:
https://github.com/templth/restlet-stackoverflow/tree/master/restlet/test-restlet-servlet
Since it use Maven, to use it, you can simply :
mvn eclipse:eclipse and then import it into Eclipse. You can then create a server (WTP) and add the project
mvn package and deploy the corresponding war into a servlet container (Tomcat or something else)
Hope it helps you,
Thierry

How to integrate Proguard obfuscation in my JavaFX's IntelliJ artifact?

I'm developing a JavaFX application using IntelliJ IDEA as the IDE.
So far, everything runs smoothly, I have all my external libs configured and my JavaFX artifact being correctly created.
Now I would like to integrate obfuscation (using Proguard) when the artifact is created.
IntelliJ have a 'Pre-processing' and 'Post-processing' option in artifact's properties where I can define an Ant task to be runned.
But I have no idea how to create that task and tell the compiler my obfuscation options.
Thank you very much in advance for any clues,
Best regards
There are 3 basic ways you do it:
Create a normal proguard.cfg file, and reference it from ant
Put your proguard settings directly inside ant using XML notation
Put your proguard settings directly inside ant using the proguard.cfg format
Here's a basic example of using Proguard with Ant with the 3rd approach:
http://www.reviewmylife.co.uk/blog/2007/10/20/proguard-eclipse-ant-buildxml/
The important thing to remember about Proguard is that everything you want to obfuscate has to be inside a JAR file, and you'll need to explicitly tell it not to obfuscate certain things (like your program entry point, things you access via reflection, etc).
JavaFX creates a file used as an entry point you want to prevent obfuscating:
-keepclasseswithmembers public class com.javafx.main.Main {
public *; public static *;
}
Make sure to include Java/JavaFX libs
-libraryjars "${java.home}/lib/rt.jar"
-libraryjars "${java.home}/lib/ant-javafx.jar"
-libraryjars "${java.home}/lib/jfxrt.jar"
If you're using FXML files, you'll want to make sure your FXML files are renamed similarly to their respective controller file:
-adaptresourcefilecontents **.fxml
Anything annotated with #FXML is accessed through reflection, so don't obfuscate them:
-keepclassmembernames class * {
#javafx.fxml.FXML *;
}
The Proguard website has a lot of information, but it can be difficult to grok.
Honestly, there are plenty of examples on the web that show you how to do this. Just google javafx proguard, and you'll probably find some good complete examples.
Edit: as far as how IntelliJ passes information to Ant.. I don't know. There are probably some variables it passes in that you reference like a normal Ant propertly. I'm sure JetBrains website has info on that on their website if you can't find it on the net.
If it was me, I'd just create an ant script to compile my application without obfuscation, then add in proguard once you've got that squared away.
Just some complementing information, regarding running an Ant task in idea's 'post-processing'.
Make sure you have a 'default' target. Else the task wont execute. Example of build.xml:
<?xml version="1.0"?>
<project name="ant_task" default="obfuscate" basedir=".">
<target name="obfuscate">
<taskdef resource="proguard/ant/task.properties"
classpath="/opt/proguard5.2.1/lib/proguard.jar" />
<proguard configuration="proguard.cfg"/>
</target>
</project>

Jar signing in eclipse, how to resign after altering source

I had to alter some source in org.eclipse.jdt.core.dom.ASTNode, I used various eclipse plugins as "headless" libraries in a application design to re-factor source code in a specific way.
I only discovered right at the very end that there was a line of code in ASTNode, that makes the application impossible.
The fastest way seemed to be to decompile comment out the line and pack the jar again.
The problem I now have is:
Exception in thread "main" java.lang.SecurityException: SHA1 digest error for org/eclipse/jdt/core/dom/ASTNode.class
at sun.security.util.ManifestEntryVerifier.verify(ManifestEntryVerifier.java:198)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:212)
at java.util.jar.JarVerifier.update(JarVerifier.java:199)
This application only needs to run once to refactor a large code base.
I'm looking for the quickest solution.
If there is some way to disable the security, in fact there is with a start up argument:
startup option -Declipse.p2.unsignedPolicy=allow
this doesn't help me since the libraries are headless. The other possible solution is to resign the jar but I assume a key would be needed or something.
Since it's a disposable application I don't need a clean fix, just anything that is quick.
the way to sign jar is using Java -cp option like below
java -cp "jcifs-1.3.17.jar:jespa-1.1.14.jar" jespa.License -u jespa_500_license_SN2136020120531.key