how to import javax.mail in eclipse? - eclipse

I am learning how to use JavaMail. (i have se11)
I downloaded javax.mail.jar,
put it under C:\Java\jdk , and extract it.
I followed the instruction, set CLASSPATH = C:\Java\jdk\javax.mail.jar ;
and I add the javax.mail.jar to the eclispe Referenced Library.
However, when i try to import javax.mail.* , it says the import can not be resolved.
I open the extracted folder, and it contains only .class files.
I tried to open the javax.mail.Session file from eclipse file explorer, but it said:
"The JAR file C:\Java\jdk\bin\javax.mail.jar has no source attachment."
what should I do in order to import the javax.mail.* ?
I am very frustrated, please help!

No matter how you run your program, to just use the classes in a jar you need to have the jar file in your classpath. If you run from the command line you can do this:
java -cp C:\Java\jdk\javax.mail.jar my.fully.qualified.classname
If you're in Eclipse then:
Import the jar file into your Java project. Use the File-->Import... action.
Select your java project and select Build Path --> Configure Build Path...
Select Java Build Path on the left
Select the Libraries tab and the Add Jars... button on the right
Navigate to and select the jar you you imported above
Click OK
The classes in the jar file are now available for use in your code.

Related

The package org.openqa.selenium is accessible from more than one module

I'm using:
Firefox 56.0.1
Selenium 3.6.0
Windows 10 home edition
Gecko Driver 0.19.0
The error message is
The package org.openqa.selenium is accessible from more than one
module: client.combined, net.bytebuddy"
This happens when you have added the external jars in the ModulePath.
Solution:
Remove the external jars from the node "Modulepath".
Select the node "Classpath" then add the external jars.
Review that all the jars are under the node "Classpath".
The problem is that you are adding .jar files to your Modulepath instead of Classpath.
Go to
Project → BuildPath → Config BuildPath
click Remove Jars from Modulepath
then click on classpath → Add external selenium jar files
Add all the required jar files inside classpath instead of module path. The same issue was also occurred with me but after adding the jars to classpath it got resolved.
I don't know anything about Selenium, but it looks like you have two modules that contain the exact same package name inside of them:
client.combined
net.bytebuddy
So when you say e.g. import org.openqa.selenium.WebDriver Eclipse doesn't know if you want to use that package from client.combined or from net.bytebuddy.
You need to either add a prefix in that import statement that will specify whether you're importing package org.openqa.selenium from client.combined or from net.bytebuddy.
You can possibly do this by just doing:
import client.combined.org.openqa.selenium.WebDriver
import client.combined.org.openqa.selenium.firefox.FirefoxDriver
or
import net.bytebuddy.org.openqa.selenium.WebDriver
import net.bytebuddy.org.openqa.selenium.firefox.FirefoxDriver
You can also try removing either of the packages (client.combined or net.bytebuddy) from your project
Add required JAR in class path instead of module path. Also delete unnecessary JARs which might have reference to the mentioned package.
I had the same error and removing the reference to one of the jar files solved the issue.
Remove the reference to one of the jar files that you added in java build path.
From the screen shot that you added I see you have reference to both
client-combined-3.6.0-sources.jar
and
client-combined-3.7.0.jar
both the packages have the same classes implemented.
Remove the reference to one and see if that help.
I had the same issue. I used JDK 9 and eclipse oxygen 64-bit version (Selenium 3.9.1). My first thought, it is the JDK 9, but I tested on IntelliJ IDEA JDK 9 and worked without any problem. So I installed the eclipse oxygen 32-bit version with JDK 8 (-no JDK 9 version on 32 bit) and the problem disappeared.
this happens when same java package code (package name + class name) is available in more than one jar file; for default modules every jar is exposed as Module. Modules essentially can not have same package name exported. This is more of a code cleanup task.

How to create a groovy jar with eclipse/ggts?

So I create a groovy jar but I'm not able to run it.
I'm using HelloWorld.groovy as an example
class HelloWorld {
static main(args) {
println("Hello World");
}
}
I save it as a jar like I would with any java file via export in eclipse/ggts:
right clicking groovy file in project explorer
click export
select jar File
specify jar file name
specify HelloWorld as the main class in the Manisfest file
keep all the defaults selected
click finish and create the jar
Now I try to run HelloWorld.groovy via java -jar HelloWorld.jar on my command line.
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
When I export it also allows me to export .classpath into my jar.
Shouldn't that include my groovy-all.jar that my GGTS is using?
Am I missing something?
I've been successful with using GroovyWrapper to create groovy jars. I want to see if it's possible with just my IDE.
I think that in eclipse you export an executable jar and that gives the option to package the dependencies?

Trouble running jar file created by Eclipse

I exported my Eclipse project as a runnable Jar file, added a manifest, as well as the appropriate class files with the command:
jar cfm JarFile.jar manifest.txt *.class
However, when I try to run the jar file with
java -jar JarFile.jar
I get the error that it "Could not find or load main class" etc. etc.
The structure of my manifest.txt file looks like this:
Main-Class: EclipseProjectName.src.packagename.mainclassname
(With a carriage return at the end)
Is something wrong with my manifest file? If not, what may be the reason that the main class cannot be found?
Thank you!
The manifest file extension should be .mf i.e manifest.mf. See here for jar file specification
Suggest to use fat jar eclipse plugin for exporting java projects as runnable jars.
Edit
Correct the content of manifest.txt as shown below
Main-Class: EclipseProjectName.src.packagename.mainclassname
project name and src are not required. Refer this
The entry in the META-INF/MANIFEST.MF entry in the finished jar file should be
Main-Class: packagename.mainclassname
and should correspond exactly to
/packagename/mainclassname.class
in your jar file (or jar file_s_ if you use Class-Path too).

Eclipse Dynamic Web Project Error - The imports org.apache.axis2.om Cannot Be Resolved

My Eclipse project underlines in red the imports below 'org.apache.axis2.om' with message...
'The imports org.apache.axis2.om Cannot Be Resolved'
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.OMNamespace;
What is the cause and how can I fix it in Eclipse..?
Regards,
You need to add axis2-kernal jar to your project. This can be done by right clicking your project then click build path -> configure build path -> libraries - add external jars, then you can add this jar from your system to your project.

How do you ensure a Utility Projects library dependency gets packaged in the final EAR in Eclipse Galileo?

I have a 'Utilty Project', and an 'EAR Project' that includes that 'Utility Project'. All the classes from the 'Utility Project' end up being packaged as a JAR and placed within the 'lib' directory of the exported EAR, for example:
EAR.ear
META-INF
MANIFEST.MF
lib
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
However, the 'Utility Project' relies on a library (freemarker.jar) that has been added to the build path using 'Properties > Java Build Path > Libraries'. All I want to do is to get freemarker.jar added to the EAR as follows:
EAR.ear
META-INF
MANIFEST.MF
lib
**freemarker.jar**
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
By searching around within Eclipse I've found 4 potential avenues for achieving this, none of which have worked. If someone can just cut to the chase and tell me what I should actually do, that would be great. But just in case, I'll iterate them here:
From the 'Utility Project' Properties:
If I click 'Java Build Path > Order and Export' and select 'freemarker.jar' for export, the jar does not end up in the EAR file at all.
If I click 'Java EE Module Dependencies' and select the 'freemarker.jar' library as a dependency, it says:
This JAR is a bundled library of an
EAR project and is supposed to be
packed in the EAR's library directory.
It conflicts with the manifest class
path dependency you are trying to
create. If you create this dependency,
the JAR will be packed in the root
(not library) directory of the EAR.
Are you sure you want to proceed?
From the 'EAR Project' Properties:
If I click 'Java EE Module Dependencies > Add JARs...' and navigate to the 'freemarker.jar', and make it a dependency, it gets added to the root of the EAR:
/freemarker.jar
If I do the same as above, but check the 'In Lib Dir' checkbox, it gets added into the lib folder, but contained within another lib folder:
/lib/lib/freemarker.jar
Thanks.
I've managed to solve this problem. In the Problems window I was getting the following warning:
Classpath entry /utility-project/lib/freemarker.jar will not be exported or published.
Runtime ClassNotFoundExceptions may result.
What I tried, at a whim, was to use the Ctrl-1 key combination I've been using to get quick fix solutions for my source code. It turns out this also provides quick-fix solutions for for the given errors and warnings. I chose the first of the two options:
Mark the associated raw classpath entry as a publish/export dependency.
and my problem disappeared!
Bizarrely, all this seems to have done is to cause the 'freemarker.jar' lib to be selected in the 'Java EE Module Dependencies' properties dialog, which I was doing myself anyway. This may be an Eclispe bug!
#MonoThreaded: After using the quick fix > Mark the associated raw classpath entry as published/export dependency, if you right-click on the project > properties > depolyment assembly you will notice that eclipse has added a new entry, something like source: /freemaker.jar, deploy path: ../lib. You can do that too, by selecting Add > Java Build Path Entry.