Trying to import the "custom" library "Htmlunit" in my project. I use the IDE Netbeans and have done the following:
Right click "Library"
Clicked "Add Library"
Created the Library and added it
I then want to import the jar "htmlunit-2.15" but Netbeans tell me the following:
'.' expected
I have tried the following formatting:
import htmluni-2.15;
import htmlunit-2.15.*;
import Htmlunit;
import Htmlunit.*;
I have read other threads here, but do not understand to the fullest how I accomplish this.
Image: [http://s8.postimg.org/7ru7csh5h/import.png][1]
It doesn't work that way, you import in your code actual classes, not jars. I suggest you reading more about classpath, since it's a basic topic.
Probably you need to open the jar archive and see it's internal directory structure. When a class you are interested in a class is located, say, under file.jar -> com/example/Utils.class, you need to import it using:
import com.example.Utils
Create new project Maven->Java Appliacation. Find file pom.xml, and add this
<dependencies>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
Maven automatically download the library and add them to project.
Related
I have a jhipster generated application using maven with java springboot on the backend. I want to add the ical4j library to the project so under the <dependencies> tag in the pom.xml file I added the lines like explained here . However when I add import org.mnode.ical4j; the maven compiler throws an error package org.mnode does not exist .
This seems pretty trivial but I don't get what I am missing.
Thank you
From what I can see in the official GitHub repo (ical4j/ical4j) the correct package to import starts from net.fortuna.ical4j. Example:
import net.fortuna.ical4j.util.DefaultEncoderFactory;
I am trying to understand what I am doing wrong with junit-tests in Maven with eclipse. Mainly I have been just following this "getting started guide" for Maven:
https://spring.io/guides/gs/maven/
But for me it is not completely working like that when it comes to junit.
To follow the exact folder-structure from the example I have named my packages under src in eclipse:
main.java.hello
test.java.hello
My test class GreeterTest.java is in the package test.java.hello and has this content:
package test.java.hello;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import org.junit.Test;
import main.java.hello.Greeter;
public class GreeterTest {
private Greeter greeter = new Greeter();
#Test
public void greeterSaysHello() {
assertThat(greeter.sayHello(), containsString("Hello"));
}
}
In my pom.xml you find the dependency:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
Unfortunately eclipse sais "the import org.junit cannot be resolved."
If change the scope of the dependency from test to compile I do not get this error message, but that would be not the way how the scope is intended to be used, is it?
What do I need to change that also eclipse understands, that this class is a test-class and therefore all dependencies are actually available?
Best,Nils
The issue appears to be related to where Eclipse thinks your source tree starts. You have put your code in src/main/java/hello and src/main/test/hello but Eclipse thinks the source tree starts at src. So it thinks the other folders are packages and has given your classes package names like main.java.hello.Greeter.
The quickest way to fix this is to run on the command line:
mvn eclipse:eclipse
which uses maven to fix your eclipse projects. It will automatically set the source root to be the correct values. When it completes, right click on the project and select Refresh to see the updated project.
To fix this manually, you can right click on the project and choose Build Path > Configure Build Path and, in the Source tab on the right, ensure that the entire src/main/java (right up to java!) is included as the source folder. Do this by clicking Add Folder and selecting java in the tree under src - main. Do the same for src/main/test. Usually maven projects include src/main/resources as a source folder too.
FYI, I'm new to Java development and Netbeans!
I have downloaded the MigLayout jar files, both core and for swing, and added their path in the NetBeans 8.2 IDE under 'Tools->Libraries->Library_Classpath'.
My problem is that I'm trying to use the API MigLayout() but every package name that I've tried to import it results in the error "package 'Package_Name' does not exist"
The following package names fail at compile time:
import MigLayout;
import net.miginfocom.MigLayout;
import net.miginfocom.swing.MigLayout;
The following package names only fail at run time:
import net.miginfocom.layout.Grid;
import net.miginfocom.swing;
import net.miginfocom.miglayout;
Links to the MigLayout forum are broken, and none of the tutorials I've seen have the import statements. All I am asking for is a link to or list of the packages needed to use MigLayout.
If MigLayout is no longer supported, it would be nice to know that as well!
Of all packages you mentioned, the following are actually working:
import net.miginfocom.swing.MigLayout;
import net.miginfocom.layout.Grid;
It is not enough to set the jar files in the library configuration of NetBeans (Tools > Libraries). You also need to set it inside your project to get your classpath working.
In the projects view, locate the directory called Libraries (JDK will be located there) and right click on it, then click on Add Library and choose the library where you defined your jar files, in your case Library_Classpath.
I'm relatively new to JIRA plugin development and as I'm working through various tutorials I've run into a problem where I can only import certain JIRA java classes. For instance, when trying to compile this tutorial to create a custom search request view https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/search-request-view-plugin-module I found that I can successfully import the following packages:
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchRequest;
but cannot import these packages:
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.issue.search.SearchProviderFactory;
Both SearchProvider and SearchProviderFactory are present in the javadocs for the latest version of JIRA, yet I can't import them despite them being in a package from which I've already imported.
Why is this? I suppose it's some sort of dependency issue but I can't seem to find a way to fix it. I'm developing in Eclipse, by the way.
Any help is appreciated. Thanks!
The problem was that in the generated pom.xml for JIRA plugin projects, the jira-core dependency is commented out. To access all developer classes, the following must be enabled.
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
I'm developing a Glassware for Google Glass. I'm trying to import these files:
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.oauth2.Oauth2;
import com.google.api.services.oauth2.model.Userinfo;
but I'm getting errors on them. They are below:
The import com.google.api.client.json.jackson cannot be resolved
The import com.google.api.services.oauth2 cannot be resolved
The import com.google.api.services.oauth2 cannot be resolved
I'm not sure why I'm getting these errors. I'm building off of the quickstart java project. My Maven Dependencies are below:
C:\Users\Family3\.m2\repository\com\google\apis\google-api-services-mirror\v1-rev20-1.16.0-rc\google-api-services-mirror-v1-rev20-1.16.0-rc.jar
C:\Users\Family3\.m2\repository\com\google\api-client\google-api-client\1.16.0-rc\google-api-client-1.16.0-rc.jar
C:\Users\Family3\.m2\repository\com\google\oauth-client\google-oauth-client\1.16.0-rc\google-oauth-client-1.16.0-rc.jar
C:\Users\Family3\.m2\repository\com\google\http-client\google-http-client-jackson2\1.16.0-rc\google-http-client-jackson2-1.16.0-rc.jar
C:\Users\Family3\.m2\repository\com\google\http-client\google-http-client\1.16.0-rc\google-http-client-1.16.0-rc.jar
C:\Users\Family3\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar
C:\Users\Family3\.m2\repository\org\apache\httpcomponents\httpclient\4.0.1\httpclient-4.0.1.jar
C:\Users\Family3\.m2\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar
C:\Users\Family3\.m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar
C:\Users\Family3\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.1.3\jackson-core-2.1.3.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\jetty\6.1.14\jetty-6.1.14.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\servlet-api-2.5\6.1.14\servlet-api-2.5-6.1.14.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\jetty-util\6.1.14\jetty-util-6.1.14.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\jetty-plus\6.1.14\jetty-plus-6.1.14.jar
C:\Users\Family3\.m2\repository\geronimo-spec\geronimo-spec-jta\1.0.1B-rc4\geronimo-spec-jta-1.0.1B-rc4.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\jsp-2.1\6.1.14\jsp-2.1-6.1.14.jar
C:\Users\Family3\.m2\repository\org\eclipse\jdt\core\3.1.1\core-3.1.1.jar
C:\Users\Family3\.m2\repository\ant\ant\1.6.5\ant-1.6.5.jar
C:\Users\Family3\.m2\repository\org\mortbay\jetty\jsp-api-2.1\6.1.14\jsp-api-2.1-6.1.14.jar
C:\Users\Family3\.m2\repository\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar
C:\Users\Family3\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.9.11\jackson-core-asl-1.9.11.jar
C:\Users\Family3\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.11\jackson-mapper-asl-1.9.11.jar
C:\Users\Family3\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar
C:\Users\Family3\.m2\repository\commons-logging\commons-logging\1.1.2\commons-logging-1.1.2.jar
C:\Users\Family3\.m2\repository\commons-codec\commons-codec\1.7\commons-codec-1.7.jar
C:\Users\Family3\.m2\repository\com\google\guava\guava\14.0.1\guava-14.0.1.jar
Why am I getting these errors? Am I not importing a .jar? I can't find any .jar's that aren't included that should be, but there could be one. Thank you for your help.
Add the client libraries to the project.
See download and setup instructions for google-api-java-client.
try adding:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-oauth2</artifactId>
<version>{version}</version>
</dependency>