I can't add epubcheck jar to my code in netbeans - java

In the folder Libraries I added the folder that contains the jar file of epubcheck (http://code.google.com/p/epubcheck/). But for some reason it does not work.
I also added this line of code:
import com.adobe.epubcheck.api;
Am I missing something?
UPDATE
Even with all the jars in the Libraries folder... It still does not work.
Here is the instructions for adding lib to the code from epubchecker README:
USING AS A LIBRARY
You can also use EpubCheck as a library in your Java application.
EpubCheck public interfaces can be found in com.adobe.epubcheck.api
package. EpubCheck class can be used to instantiate a validation
engine. Use one of its constructors and then call validate() method.
Report is an interface that you can implement to get a list of the
errors and warnings reported by the validation engine (instead of the
error list being printed out).
OUTPUT
deps-jar:
Created dir: /Users/.../NetBeansProjects/epubValidation/build
Updating property file: /Users/.../NetBeansProjects/epubValidation/build/built-jar.properties
Created dir: /Users/.../NetBeansProjects/epubValidation/build/classes
Created dir: /Users/.../NetBeansProjects/epubValidation/build/empty
Created dir: /Users/.../NetBeansProjects/epubValidation/build/generated-sources/ap-source-output
Compiling 1 source file to /Users/.../NetBeansProjects/epubValidation/build/classes
/Users/.../NetBeansProjects/epubValidation/src/epubvalidation/EpubValidation.java:6: package com.adobe.epubcheck does not exist
import com.adobe.epubcheck.api;
1 error
/Users/.../NetBeansProjects/epubValidation/nbproject/build-impl.xml:915: The following error occurred while executing this line:
/Users/.../NetBeansProjects/epubValidation/nbproject/build-impl.xml:268: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 9 seconds)

Remove the /Users/... entry from your libraries. Adding a folder in the classpath doesn't add all the jars in that folder, it adds the folder as if it were a jar. It's trying to read that folder as if it contains the .class files, which is incorrect. Instead, select the external jars option and add all the jars in lib, much like how you probably added the epubcheck jar.
An alternative: use Maven. It will do all this library management for you, and Netbeans makes it pretty easy to use. Here's a tutorial.

You have already done the following:
a) Add the epubcheck jar to Libraries
right-click on Libraries & select "Add JAR/Folder...", navigate inside your directory
/Users/xxx/epubcheck-3.0b5-db & select epubcheck-3.0b5.jar
b) Add the entire epubcheck folder to Libraries
right-click on Libraries & select "Add JAR/Folder...", navigate to directory
/Users/xxx/epubcheck-3.0b5-db & select it
a) is correct
b) is incorrect - you should add each individual jar file within /Users/xxx/epubcheck-3.0b5-db/lib
To correct, do this within Netbeans:
c) Remove (b) as follows
right-click Libraries->/Users/xxx/epubcheck-3.0b5_db and select Remove.
d) Add batik-css-1.7.jar within epubcheck lib folder to Libraries
right-click on Libraries & select "Add JAR/Folder...", navigate to directory
/Users/xxx/epubcheck-3.0b5-db/lib & select batik-css-1.7.jar
e) repeat (d) for each of batik-util-1.7.jar, commons-compress-1.2.jar, jing-20120227.jar, sac-1.3.jar, saxon-9.1.0.8.jar
Alternative Solution
You could add all of /Users/xxx/epubcheck-3.0b5_db as a separate Netbeans project:
i) copy/move /Users/xxx/epubcheck-3.0b5_db to
netbeansWorkspaceFolder/epubcheck-3.0b5/epubcheck-3.0b5
ii) move epubcheck-3.0b5.jar to netbeansWorkspaceFolder/epubcheck-3.0b5/epubcheck-3.0b5/dist/epubcheck-3.0b5.jar
iii) add it as a Netbeans project:
Add Project -> Java -> Java with existing Sources -> Next ->
set project name=epubcheck-3.0b5 -> Browse -> select epubcheck-3.0b5 directory -> Next ->
for source package folder select "Add Folder..." and select "epubcheck-3.0b5/epubcheck-3.0b5" -> Next ->
Included files list should now show all required lib jars (lib/*.jar) -> Finish
iv) select epubValidation project -> Libraries folder & right-click & select "Add Project..." & select "epubcheck-3.0b5" project
v) Now dist/epubcheck-3.0b5.jar of the lib jars within epubcheck-3.0b5 are available to epubValidation
=B)

To import the epubcheck you need to do the following:
Create a new Java project... Unchecked Create Main Class, this is the only way to make it work.
Right click on Libraries to select Add JAR/Folder...
Add JAR...
Add the other JARs.
New File... New Class...
Make sure that the package input is empty.
Write the import...
There you go.
I am not really sure why you have to do it this way... But that is the only way I found to solve the problem.

Related

CLOSED - How do I import another class not in Java Library

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.

how to import file from one eclipse project to another

I know this question must have been asked before and i have gone through the solution but that didnt seem to solve my question.
Suppose I have 2 projects in eclipse .ProjectA and ProjectB and ProjectA has file named FileA in package PackageA and ProjectB has a file named FileB in PackageB.Suppose i want to use a function of FileA in projectB.Is there any import statement which will allow me to do so.I dont want to copy paste the entire fileA in projectB.I just want something like
import ProjectA.packageA.fileA
class fileB
{
//calling function from fileA
int somethingsomething = fileA.somefunction();
}
I have done things like go to project right click and click on import and import the file.But i dont want the file to be present in my filelist of ProjectB.Please ,Can someone help me with this problem.Is this even possible?
First way
Right click on ProjectA and export as jar file.
Right click on ProjectB, Goto Build path -> Configure build path -> Libraries
Add external jar of ProjectA
Second Way,
Right click on ProjectB, Goto Build path -> Configure build path -> Projects
Click on Add, select ProjectA from list.
After this, you will be able to import classes in ProjectB which are defined in ProjectA by,
import packageA.fileA
Read more at : Java build path
Well your Project B needs the code of File A to execute it. You can either copy the file, or a .jar, or you copy the relevant code into the new project. You cannot just reference a piece of code but not add it to your Project in some way. When building your project to a .jar for example, this piece of information must be present and accessible for the program.

Eclipse: Getting error when adding external class / jar files to build path: "XYZ Cannot be resolved to a type"

I am working with Java and Eclipse, which are both a bit out of my comfort zone (yup , this is an assignment...).
I have 2 class files which I need to use in my project. So far I have tried:
Attempt #1
I tried adding an external class folder:
In my project folder I have added classes\legacy folder.
In Properties > Java Build Path > Libraries I Clicked on the Add External Class Folder
In the window that opened I selected the classes folder created in step 1.
In my code I have added import legacy.*;
Result:
I can use the classes in the class files but getting the following errors:
(seems to occur when the classes are attempting to use one another)
The project was not built since its build path is incomplete. Cannot
find the class file for IshKesher. Fix the build path then try
building this project
The type IshKesher cannot be resolved. It is indirectly referenced from required .class files
Note: tried for class folder as well - same results.
Attempt #2
Someone suggested that using jar files should be easier, so I gave it a try:
Created a jar file containing the class files: jar cvf classes.jar ContactsList.class IshKesher.class
Added the jar file to the build path using this tutorial.
Result:
Getting an error for each usage of classes in the jar file:
XYZ Cannot be resolved to a type
Any Ideas how make the class files available in my code?
EDIT:
It turned out that Attempt #2 worked once using my source files in the default package (cannot figure out why though...).
Try my instructions.
If you don't want to include copy of Borat.jar, but only want to reference it from an external folder, then just do this one step -
No copy step -
Your java project > Right click > Build path > Configure
build path > add EXTERNAL jars button > select your jar
> ok.
If you want that jar to become a part of your java app, ie create a copy of the jar in your java app, then use the steps below.
Step 1- Create a lib folder in your app to store all jars
Your java project > Right click > New Folder > Folder Name = lib
Step 2 - Import all copies of the necessary jars into lib folder
Your java project > lib folder > Right click > import > General -->
File System > From Directory = The directory where you stored your jar files.
> ...You should now see the jars in that folder. Lets say we want to import
Borat.jar > Finish.
Step 3 - To check if step 2 is done correctly
Your java project > lib folder > Expand the lib folder to see its
contents. Borat.jar should be listed there. Nice !
Step 4 - Finally, to add the jars to the project
Your java project > lib folder > Right click > Build path > Configure
build path > add jars button > expand your project > expand lib folder
> Select Borat.jar > ok.

Import error in Java

jp.co.wap.exam.lib.Interval can not be resolve
I am trying to define an interval like this:
Interval interval1 = new Interval ("08:00"."09:00");
It's giving the error Interval can not be resolve. I am using Eclipse. I hover the cursor over the Interval text but there is not option for import. How can I resolve the import problem?
You need to add the library (a jar file) in the classpath.
In eclipse, select your project folder and go to navigation bar:
Project -> Properties -> Java Build Path -> Add External JARs (or Add JARs, depending on where your jar file is).
The Jar containing the Interval class is not on the class path.

How do I import ShowcaseView in Eclipse?

ShowcaseView is contained in a Zip file here. But what exactly am I downloading and how do I import it in Eclipse?
After 2 days I succeed, I have created steps to import ShowcaseView in Eclipse that may be helpful to you.
How to use Showcase View in Eclipse.
Download ShowcaseView from github and extract.
Now Follow step for import.
- Right click on Project Explorer
- Import -> Android -> Existing Android Code Into Workspace
- Select Extracted "ShowcaseView-master"
- Check both project "library" and "MainActivity"
- Check "Copy projects into workspace"
- Finish.
(After importing you can see 2 projects imported namely "main" and "SampleActivity", you may change "main" as "libShowcaseView" and "SampleActivity" as "ShowcaseViewDemo" so you can easily identify. :) )
May you see error in "ShowcaseViewDemo" (Dont worry...), See src/ folder is also blank (in both "libShowcaseView" and "ShowcaseViewDemo") :) right??? Dont mind.
Make following packages in "libShowcaseView" project. See Example.
- com.github.amlcurran.showcaseview
- com.github.amlcurran.showcaseview.targets
and Move all java files from /java/com/github/amlcurran/showcaseview and /java/com/github/amlcurran/showcaseview/targets Respectively.
Make following packages in "ShowcaseViewDemo" project. See Example.
- com.github.amlcurran.showcaseview.sample
- com.github.amlcurran.showcaseview.sample.animations
- com.github.amlcurran.showcaseview.sample.legacy
- com.github.amlcurran.showcaseview.sample.v14
and move files as above (from java folder respectively).
Now right click on "libShowcaseView" project->properties->Android->Move down and check "Is Library" then add "actionbarsherlock" as Library. See Preview
Now Add as library in ShowcaseViewDemo. Goto properties of "ShowcaseViewDemo"->Android->Add->select "libShowcaseView"->Ok...
I think you didn't ran into error now. You can Run.
You can ping any time for any suggestion or help.
Happy ShowcaseViewing...
Easiest way is:
Create an empty Android Application project in your Eclipse workspace.
Copy files in ShowcaseView/library/ folder of github to your new project base folder.
Refresh project in Eclipse.
Goto project properties - Android and select "Is Library"
Clean unnecessary stuff and build.
It should be ready to add as dependency of your app.
Alternatively you can pick another library project .project file and copy it inside this library folder, edit it to match your new project name, etc... And then import in Eclipse. But this is more hardcore if you don't know what you're doing.
Soure : How do I build these libraries from GitHub
Following ツ Pratik Butani ツ's Answer and use Android Support Library to replace ActionBarSherlock
In project.properties of libShowcaseView and ShowcaseViewDemo
add target=android-21
Right click on "libShowcaseView" Properties->Android->Library->Add... select AppCompat(android support library v7)->Ok
In styles.xml of ShowcaseViewDemo
Change
android:Theme.Holo.Light, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar to Theme.AppCompat
Remove <item name="android:fontFamily">sans-serif-light</item> in ListItemBigText
In ActionItemsSampleActivity.java
change SherlockActivity to ActionBarActivity, getSupportMenuInflater to getMenuInflater.
In MultipleActionItemsSampleActivity.java
change SherlockActivity to ActionBarActivity
change com.actionbarsherlock.app.ActionBar.OnNavigationListener to android.support.v7.app.ActionBar.OnNavigationListener
changegetSupportMenuInflater to getMenuInflater
Do it in there steps:
Download ShowcaseView from github`
Create package com.github.amlcurran.schowcaseview and com.github.amlcurran.schowcaseview.targets in your eclipse project.
Extract ShowcaseView-master.zip or rar.
Go to library/src/main/java/ and copy com/github/amlcurran/showcaseview java files in com.github.amlcurran.schowcaseview package.
Do same thing for com/github/amlcurran/showcaseview/targets in com.github.amlcurran.schowcaseview.targets.
Finally, copy others files in differents folder drawables, layouts, value(copy in the old value files, style.xml for example).

Categories

Resources