Can't import class from jar file in IntelliJ - java

So I am trying to import this class from my jar file. IntelliJ recognizes access to all the folder structures but not the class.
Says: "Cannot resolve symbol 'Constants'.
Note that I have tried clicking "Add library 'premiumdue.main.jar' to classpath" and it still doesn't work.
I have no idea why it won't let me import the class.
Here is a minimal intellij project showing my issue: https://www.dropbox.com/s/xzvv2x1ca2lld26/jar_issues.zip?dl=0

For your sample Gradle project, the dependency jar has to be referenced in build.gradle file as described in this answer.
dependencies {
implementation files('../create_jar.jar')
}
Proof:

Related

How do I set up extJWNL in a Java project?

I am trying to determine whether a set of strings, from an English sentence, are all words from the WordNet dictionary. I put the JARs in a folder in my project in eclipse.
I've downloaded the binary release of extJWNL and put the JARs in a folder called lib.
I also added these jar files to the class path and the module path using Right Click > Build Path > Configure Build Path:
I used the following code to try to import dictionary
import net.sf.extjwnl.dictionary;
This error is shown on the import statement
The package net.sf.extjwnl.dictionary is accessible from more than one module:
<unnamed>, extjwnl
I thought that this error was showing up because it was a package, not a class/type. But adding a new class and trying to change the package doesn't show this new package, namely WORDNET_JARS, just the default package.
Why is this error being returned and what do I need to do to get rid of the error and import the wordnet packages?
Platforms
I am using Eclipse IDE, and write all this code in Java. The API I am trying to import is the WordNet API.
Edit (8/21/2019)
By removing the module path, it gives a new error:
Only a type can be imported. net.sf.extjwnl.dictionary resolves to a package
I'm surprised it was this easy:
Instead of
import net.sf.extjwnl.dictionary
I had to do
import net.sf.extjwnl.dictionary.*
to get all the types. The only other thing that had to be done had already been done where I add the JARs to the class path

import packages in cordova plugin

I'm building a plugin for a PDA3505 device, which must print texts using the integrated printer.
In the plugin's main Java file, I have this import: import com.pda3505.printer.PrinterClassSerialPort;
When I add the plugin to my app and try to make a build, I get this error:
error: package com.pda3505.printer does not exist
import com.pda3505.printer.PrinterClassSerialPort;
Where do I have to put the package for the plugin to work?
If you have .jar files for the PDA SDK, then you have to put it in a folder within the code and add a lib-file entry in the plugin.xml so it's copied to your project.
<lib-file src="src/android/libs/lib.jar"/>

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

How do I install TestFX?

I'd like to put together a set of jUnit tests under Eclipse (Neon) on Windows to automate the testing of JavaFX GUIs. It seems that TestFX is the bee's knees for this kind of thing, but having looked around the internet quite a bit, I'm still not sure how to install TestFX without using Maven or Gradle.
I am not familiar with Maven and Gradle, and trying to follow the simple instructions to install TestFX via Maven was unsuccessful. This was done under Eclipse Mars, after which my simple GUI program threw up a compile error about not being able to find or load main class and a run-time error that Selection does not contain a main type. (The simple GUI program ran without errors previously.) After this, I downloaded the latest Eclipse Neon and tried to start afresh.
This is what I did:
Download and install Eclipse Neon from eclipse.org.
Create a Java Project called TestProject (execution environment JavaSE-1.8).
Grant access to javafx/** (right-click on project -- properties -- Java Build Path -- Libraries -- JRE System Library -- Access Rules -- add).
Create MyClass with minimal contents:
package test;
import javafx.application.Application;
import javafx.stage.Stage;
public class MyClass extends Application {
#Override
public void start(Stage stage) throws Exception {
stage.setTitle("Hello World");
stage.show();
}
}
Copy the file testfx-core-4.0.0-20150226.214553-8.jar from the testfx repository (linked from the Via direct download section of How to use TestFX in your project) into my eclipse project, sitting at the same level as the JRE System Library;
Add the jar file to the build path (right-click on project -- properties -- Java Build Path -- Libraries -- Add JARS) - this automatically created a directory called Referenced Libraries and copied the jar file into it; and
Create a JUnit test (right-click on source folder -- New -- JUnit Test Case), filling in the appropriate package and Class under test fields, and giving the test case a name (MyTest).
Then I tried to extend the class MyTest to use testfx:
class MyTest extends GuiTest {} as advised in this link; and (separately)
class MyTest extends ApplicationTest{} as advised in this link.
Here's the code in the second case:
package test;
import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest;
public class MyTest extends ApplicationTest { }
In each case, eclipse complains that the superclass GuiTest / ApplicationTest cannot be resolved to a type.
I suspect that the problem is that I haven't properly installed testfx. Can anyone help?
There are multiple dependencies; the following jar files must be added to the Referenced Libraries (after copying the jar files into the project, right-click on the project -- Properties -- Java Build Path -- Libraries -- Add JARs...).
testfx-core-4.0.4-alpha.jar, source: http://mavensearch.io/repo/org.testfx/testfx-junit/4.0.4-alpha
testfx-junit-4.0.4-alpha.jar, source: http://mavensearch.io/repo/org.testfx/testfx-core/4.0.4-alpha
guava-18.0.jar, source: http://mavensearch.io/repo/com.google.guava/guava/18.0
hamcrest-core-1.3.jar, source: http://mavensearch.io/repo/org.hamcrest/hamcrest-all/1.3
The above is independent of Gradle and Maven. Alternatively, the files can also be pulled using Gradle:
Create a Gradle project in Eclipse.
In the dependencies block in build.gradle, insert the following lines (source):
testCompile "org.testfx:testfx-core:4.0.+"
testCompile "org.testfx:testfx-junit:4.0.+"
Right-click the project -- Gradle -- Refresh Gradle Project
This places the required files into the Project and External Dependencies folder.
Useful tutorial for TestFX 4: https://www.youtube.com/watch?v=NG03nNpSmgU.

The import javazoom cannot be resolved

hi all
i use the javazoom.jl.player.Player package but it is says The import javazoom cannot be resolved. i am using eclipse and doing Android project. i clean the project still the same error is shown. please correct me.
If eclipse can't resolve a package fragment of an import statement, then it tells you (with that error), that there is no library on the classpath that contains a class from that package (or from a package whose name starts with the missing part).
An easy way for standard java/eclipse:
create a folder lib in your projects root directory (with the eclipse workbench!)
copy and paste the jar into that folder
right-click the copied jar and select "add to build path".
This should eliminate the compiler errors immediately.
(Previous part of the answer)
Taking the error message literally, it looks like you have a line of code like that:
import javazoom;
This would be wrong, because we don't import packages but classes from a package. To import all classes from the javazoom package, we'd say:
import javazoom.*;
You should download the .jar of jLayer ( http://www.javazoom.net/javalayer/sources.html )
And add into classpath in the way Andreas_D told you.

Categories