Java fitting websites forms. Compilation problem - java

I have found many tutorials, which showed me how to connect with websites and fit some forms, but almost all of them contained small piece of code - without imports, I figured out that i need to use special library like htmlUnit or Watij, so I downloaded it, and tried to use but i couldn't. I have tried putting all jar files from downloaded zip archive to lib folder in java compile but it didnt work. I have also try to compile with
-classpath - but it didn't work - probably I used it in wrong way, all time i m getting .
Main.java:5: error: package [...] does not exist.
How can I add library to java compiler or how can I compile file with library properly.
I m using windows and jdk version: 10.0.1, also i m not using any advanced java editor like eclipse.
So in conslusion:
import gargoylesoftware.htmlunit.WebClient;
import gargoylesoftware.htmlunit.html.HtmlElement;
import gargoylesoftware.htmlunit.html.HtmlOption;
import gargoylesoftware.htmlunit.html.HtmlPage;
import gargoylesoftware.htmlunit.html.HtmlSelect;
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient.getPage("http://some_url");
I have got something like this in my code and i m trying to compile it (after putting jar files from zip(https://sourceforge.net/projects/htmlunit/) in lib folder (located in jdk folder)) with this command:
javac Main.java
and this(where zipo.zip is downloaded archive from upper link):
javac -classpath watij.jar Downloading.java
but for every import it ended in this compilation error:
Main.java:6: error: package gargoylesoftware.htmlunit.html does not exis
Thanks

I know that it was hard to understand my problem.
I managed to find a solution while trying to paraphrase the problem.
The thing, which i was doing in wrong way is exactly the same as in article below.
How to compile Java program with .jar library

Related

I keep getting "error package com.mongodb does not exist" when trying to compile MongoDB Utilites class

I am running a webapp using a connection to MongoDB where products reviews are stored. The current version of the webapp works correctly. (i.e. it writes and stores new reviews in the MongoDB collection).
Nonetheless, when I make changes and try to compile a new version of the MongoDB Utilities class I keep getting:
error package com.mongodb.XXX does not exist
import com.mongodb.BasicDBObject;
^
I do have the following .jar files in the \lib directory:
mongodb-driver-3.6.3
mongodb-driver-core-3.6.3
mongodb-java-driver-3.6.3
bson-3.6.3
and I mentioned them in the CLASSPATH variable:
set CLASSPATH=.;C:\apache-tomcat-7.0.34\lib\servlet-api.jar;C:\apache-tomcat-7.0.34\lib\jsp-api.jar;C:\apache-tomcat-7.0.34\lib\el-api.jar;C:\apache-tomcat-7.0.34\lib\commons-beanutils-1.8.3.jar; C:\apache-tomcat-7.0.34\lib\mongo-java-driver-3.6.3.jar; C:\apache-tomcat-7.0.34\lib\bson-3.6.3;C:\apache-tomcat-7.0.34\lib\mongodb-driver-3.6.3; C:\apache-tomcat-7.0.34\lib\mongodb-driver-core-3.6.3; C:\apache-tomcat-7.0.34\lib\mysql-connector-java-5.1.38-bin.jar;
What am I doing wrong? How can I get java to compile my new MongoDB Utilities class?
I couldn't reproduce the same behaviour, but I only reference mongodb-java-driver-3.6.3 in my build scripts.
Since the mongodb-java-driver is an uber JAR that contains mongodb-driver, mongodb-driver-core, and bson, you could try removing these latter three from your classpath and build scripts and see if that resolves the issue.
I was able to solve my issue so I post this answer in case someone is stuck in the same problem.
Thanks to what user "nos" posts in the answer to this question I used the -verbose option when compiling e.g.:
javac -verbose className.java
In the errors log I noticed that the Java compiler was searching for the MongoDB classes in a different \lib folder than the one I used in my CLASSPATH definition. So I added a copy of the mongodb-java-driver there and the compilation worked.
As craigcaulfield correctly mentions above there is no need to add the other drivers ( mongodb-driver, mongodb-driver-core, and bson).

Using Breeze in IntelliJ

I downloaded breeze jar files from the link, then I went to Project Structure->Modules->Dependencies and added downloaded jar files.
I made a new project->Scala class and wrote the following code:
import breeze.linalg_
object Scrpting extends App{
println("hello")
}
I get the following error.
Error:(4, 8) not found: object breeze
import breeze.linalg_
I tried to search online, but was unable to find any clear useful resource on how to use breeze with IntelliJ. Can someone please help me with this? I am using Mac OS.
In your build.sbt file, make sure you add all the dependencies listed under "libraryDependencies" at
https://github.com/scalanlp/breeze

"packaged does not exist" when compiling with javac

I am nearly complete with my internship work. One thing that is holding me back is compiling
I have a directory with three sub directories: lib, source, class. Within the source sub directory I have a GUI.
I try to run the following command to compile the GUI.
javac -cp .:lib\poi-3.11\poi-3.11-20141221.jar -d class\ .\src\GUI\*
Contents of some files withing the GUI are dependent upon Apache POI. When I run this command I get the following error:
src\GUI\CELL_TO_STRING.java:4: error: package org.apache.poi.ss.usermodel does not exist
import org.apache.poi.ss.usermodel.Cell;
Here is the imports of my java file CELL_TO_STRING:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
There are a few more but for brevity, I'll just list these. I believe this is some issue with specifying the class path to the Apache POI. Apache POI is a pretty big library with tons of jar files. So it will be hard to show you what exactly is in it. But if you could download for yourself to help out, that would be awesome.
From what I have seen on the web is "use maven", "use ant", "use this IDE". IDEs/Build Tools are very useful, I understand that. But I want to know how to properly build java programs through a terminal like ms-dos or shell. Having said that, please don't reply with the mentioned responses on other threads.
Please let me know if I need to give some more information.
Check the components page of Apache POI. Could you try after including poi-ooxml and poi-ooxml-shemas jars? These are required for ss it seems.

package org.apache.commons.collections.map does not exist import org.apache.commons.collections.map.MultiValueMap

When I used library collections for multivalue Maps on the esclipse, all things are Ok for build application.
However, when I configured xml file to run by command lines,
the error happened when running application.
Although, I copied all library that I used when run on eclipse into lib folder.
the message error: "package org.apache.commons.collections.map does not exist import org.apache.commons.collections.map.MultiValueMap"
Please tell me the way to config it.
Thanks
Try with -classpath common-collections.jar in the command line.
Package name for collection is changed from collections to collections4 with latest jar file.
How I got into this issue and solved:
I upgraded jar version to commons-collections4-4.4.jar, and got into this error.
I changed import statement in my java file, which linked to new jar as follows
Error: import org.apache.commons.collections.map.HashedMap;
New (update): import org.apache.commons.collections4.map.HashedMap;
and error resolve. Hope it may help.

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec

So I'm working on a java-made plugin of the well known Cooja Simulator..when I click on a button, I get the exception you see in the title..
I've already read many posts related to the same issue and I have put the issuing classes in the classpath environment var, in this way (I'm working on Ubuntu):
The classes contained in "com/sun/image/codec/jpeg/JPEGCodec" are located here:
"/home/user/contiki-2.6/jar_files/lib", so that the full path is "/home/user/contiki-2.6/jar_files/lib/com/sun/image/codec/jpeg/JPEGCodec".
I've edited the bashrc file and I've inserted the following line:
export CLASSPATH=.:/path1:/path2:/path3:/home/user/contiki-2.6/jar_files/lib
Where the latter one is the path where my problematic classes are located..in the source code, the classes are imported in this way:
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
And I make the Cooja Simulator starts using the command:
ant run
I've also tried to force the required jar/classes by issuing:
ant -lib /home/user/contiki-2.6/jar_files/lib/com/sun/image/codec/jpeg run_bigmem
but I got the same error.. Anyone who can help me to solve this issue? thanks a lot..
Cooja has its own classloader. To add additional jars add a lib-folder to your plugin and copy the jars into that folder. Then add
se.sics.cooja.GUI.JARFILES = + file1.jar file2.jar
to the cooja.config.
Look at https://github.com/contiki-os/contiki/tree/master/tools/cooja/apps/mspsim as an example - here the required jars are copied by Ant.

Categories