I am trying to read rss.
I copied the jar file in to my libs folder, and I added the jar file to my eclipse project as a library.
In order and export i checked my jar file.
Now I am trying to use the rss reader provided by rome
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
URL url = new URL("http://myUrlGoesHere");
XmlReader reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
I get the following error on the last line:
The type org.jdom.Document cannot be resolved. It is indirectly referenced from required .class file
What does this mean? What is the solution? * no error on imports *
In order to get it to compile I had to use the jdom-1.1.3.jar file from http://www.jdom.org/dist/binary/archive/. After the zip file is extracted it can be found in the directory jdom-1.1.3\jdom\build.
You will need to right click on your project| Select Properties | Java Build Path | Libraries | Add External JARs.
In addition to copying Rome's jar file to your libs folder, you also need to add JDOM's library (jar) to your class path.
The error you are getting says that someone is indirectly referencing JDOM's jar. Probably someone on Rome or any other library you don't control.
Related
I'm trying create a simple NFT using Java Spring Boot with Web3J dependency. When I'm trying to generate the .abi file and .bin file using Solc compiler, I'm receiving this error:
Source "#openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File not found. Searched the following locations: "".
--> src/main/resources/solidity/nfts/SimpleCollectible.sol:7:1:
|
7 | import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The message for this error is clear, I cannot import external file. How I could fix this without copying the required files into my project?
I am new in this topic and I want to integrate smart contracts with Java.
I am also facing the same Error I found one solution for this, but it also has some issues. After compiling it give abi and bin files for both contracts.
You can try this, Add an openzeppelin file path also in your command.
Found solution here
solcjs ./node_modules/#openzeppelin/contracts/utils/math/SafeMath.sol
./src/main/resources/solidity/AddressBook.sol --bin --abi --optimize -o
./src/main/resources/out
-- The first path is the openzeppelin contract path and the second is the source file path.
Normally your ide might have an option similar to this in vscode Package Default Dependencies Contracts Directory. if this configured successfully, import statement should automatically go inside node_modules and find the #openzeppeling dependency. If not you have to pass relative path in solidity code:
import "../node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";
I am writing a small Java Library (say project A) to be used externally (as a .JAR) in any other project (project B).
This is how project A looks like :
projectA
--src/main/java
--packageOne
....
--packageTwo
--A.java // need to access the next few text files in this java file
--ImportantTextOne.txt
--ImportantTextTwo.txt
--ImportantTextThree.txt
This is how project B will look like :
projectB
--src/main/java
--B.java // I will use project A here.
I have tried importing the text files, but every time I use it as a .JAR externally in ProjectB, I always get some errors such as
java.nio.file.NoSuchFileException
I presume this is because of some class path issue.
So how do i correctly read my text files in ProjectA?
thanks in advance
Edit : I don't need the text files in projectB, they are just used once to pull text from in projectA. All I want is to correctly read those files in projectA, so I can import projectA in any project and not get errors.
You placed the txt files besides the class files. You may have to move them to
src/main/resources/packageTwo
for your build process to correctly handle them. Anyway, make sure they are at the right location once the jar file is built.
To access such a file, you cannot load it from the filesystem as it is part of your jar. But it is on the classpath. So you need to access it like
URL url = A.class.getResource("/packageTwo/ImportantTextOne.txt");
// check what url you got - if it is null the resource was not found
InputStream in = url.openStream();
...
So with the help of Hiran's response and digging around (also this) I figured it out.
File structure of the library you are writing :
projectA
--src/main/java
--packageOne
....
--packageTwo
--A.java // need to access the next few text files in this java file
--ImportantTextOne.txt
--ImportantTextTwo.txt
--ImportantTextThree.txt
Whenever reading a file, treat it as a resource. As when the class will be used as an external .JAR you will not be able to access files inside the .JAR. Instead follow this type of pattern :
A.java
URL url = this.getClass().getResource("ImportantTextOne.txt") // this assumes your text file is in the same location as A.java
InputStream in = url.openStream();
String text = new BufferedReader(
new InputStreamReader(in, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
I took the java implementation of the Factual API (reference http://developer.factual.com/) and made a JAR file for factual. I did this by opening a new project in eclipse with the factual java files and then exporting to a new jar file.
I put that jar file in my coldfusion installation's /WEB-INF/lib/ folder.
After restarting Coldfusion, I tried to create a new cfobject like so
<cfscript>
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
</cfscript>
I get an error indicating that it cannot find the Factual class.
Can anybody give me some guidance?
(Summary from comments)
It sounds like you may be exporting the source files ie *.java rather than the compiled class files, ie *.class. In the Jar Export wizard, be sure to select the "Export generated class files and resources" option. (To automatically compile the project sources before expi, enable the setting: JAR packaging > Build projects if not build automatically option). If you prefer you can also find pre-compiled jars in the MVN repository.
put that jar file in my coldfusion installation's /WEB-INF/lib/
folder.
CF10+ also supports dynamic class loading via a new application level setting THIS.javaSettings.
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
Just as a point of interest, src/main/java/ is not actually part of the libary class name. It is a standard directory structure used in Maven projects. It is probably included when exporting the sources, but not the compiled classes.
You can always verify the correct path and class name either by examining the API ie javadocs or by viewing one the source files. Package declarations are always at the top of the source file, such as on line 1 of src/main/java/com/factual/driver/Factual.java:
package com.factual.driver; // ie "com.factual.driver"
.. and the class declaration on line 39.
public class Factual { // ie "Factual"
Combined that gives you the exact (case-sensitive) path to use with createObject:
factualClass=CreateObject("java", "com.factual.driver.Factual");
I have this code in my java project, which reads a file and converts it into a string.
String txt = FileUtils.readFileToString(text);
It uses this class https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html
How do I import this into my project?
Thanks :)
If you are using Ant as a build in tool then below solution works,
Step - 1: download .jar file from here,
Step - 2: Then after add it into your class path likewise,
Project right click -> properties
Step 3 : find Jar from you machine, and add it to your class path. likewise,
Click -> OK.
Now, Your problem has been resolved.
First of all you are looking for deprecated method. I suggest you should not use deprecated methods if possible.
Secondly, if you just want to get content of file in String, you can do it in following way with java.nio.file.Files and without using any third party library.
File file = new File("abc.txt");
String txt = new String(Files.readAllBytes(file.toPath()));
Include commons-io jar in build path of your project by downloading it from Apache site -
https://commons.apache.org/proper/commons-io/download_io.cgi
Try following what Rene said here:
Add commons-io dependency to gradle project in Android Studio
You can also try to drag the jar file under Jar folder of lib after downloading it, then right click on the Jar file and select the "Add as library" option. Then select your app from the dialog box.
I have an issue with path names in my code. Let's say I have a main class:
com.test.LoadFile.java
Similarly I have a myxml.xml file under com.test. Meaning that the Java file and XML file are under same package.
Can somebody suggest how, when I do (inside LoadFile)
File file = new File("???/myxml.xml")
What should the path be, to support both:
Eclipse IDE code (after including the above code into a single Java project)
and
Run the main LoadFile class outside of the IDE (in a JAR file)
What should I use as the value of the path variable to include in the generated project JAR?
You can read the XML file using getResourceAsStream(), as long as it's in the CLASSPATH:
InputStream is = LoadFile.class.getClassLoader().getResourceAsStream("/myxml.xml");
EDIT: If you are packaging into a .jar, you must specify the complete path of the resource from the jar's root folder using "/" at the beginning of string