I am trying to modify WEKA source code.
I tried the link on modify weka source code in netbeans but is no longer working. I am trying to run the WEKA java source code in Intellij and I get 100 errors (literally) coming from the weka, like
Error:(23, 44) java: package com.googlecode.jfilechooserbookmarks does not exist
Error:(28, 1) java: package no.uib.cipr.matrix does not exist
and it goes on.
I tried to import it as a Maven project because of the pom.xml dependencies. It compiles and builds without any problem, but when I try to run a Java class, ex. Main.java, it gives all the errors above.
My project structure is:
Project
-scr
--main
---java (Source Folder)
----Main.java
-weka-src
--src
---main
----java (Source Folder)
------weka
Does anyone have an idea of how it can compile without errors?
Thank you in advance!
Thanks Jens for the comment!
Indeed, there were some dependencies I needed to add to pom.xml. Now it's working. This is what I added:
<dependency>
<groupId>com.googlecode.jfilechooser-bookmarks</groupId>
<artifactId>jfilechooser-bookmarks</artifactId>
<version>0.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.vbmacher/java-cup-runtime -->
<dependency>
<groupId>com.github.vbmacher</groupId>
<artifactId>java-cup-runtime</artifactId>
<version>11b</version>
</dependency>
Related
I know that questions have been asked before, but it does not solve my problem in my school project.
I downloaded the JSON.simple jar file from https://mkyong.com/java/json-simple-example-read-and-write-json/, then move it to the src directory and import it.
In the src folder I also have Main.java, Manager.java and Peer.java, in which Manager and Peer uses the json.simple package.
I am using Intellj.
At src directory, I try to run javac Main.java, I get 14 errors including
import org.json.simple.parser.JSONParser;
^
.\Manager.java:95: error: cannot find symbol
Then I tried to provide the full path for the jar file: javac -cp C:\Users\yiges\Desktop\COMP90015\Project3\WhiteBoard\src\json-simple-1.1 Main.java
I get the 4 errors including:
imple-1.1 Main.java
Main.java:15: error: cannot find symbol
Manager manager = new Manager(port);
^
symbol: class Manager
location: class Main
Then I tried to compile all java files: javac -cp C:\Users\yiges\Desktop\COMP90015\Project3\WhiteBoard\src\json-s imple-1.1 *.java or simply javac *.java
I get again 14 errors including:
Manager.java:1: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
^
How do I solve this issue?
Thanks for helping!
if you create the project with Maven you are going to avoid all the import and compile problems and you will focus only on code. If you are new to Maven, it´s simpler than you can think. To create the proyect see this short video
Working with Maven in IntelliJ IDEA
Then you can easily import JSON.simple library adding the following dependency to pom.xml file, inside tags:
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
In real projects you are going to use Maven or Gradle, so the soon you learn that is better. If continue with errors even with Maven or you need to solve this without Maven, post a reproducer or even your project.
Problem solved.
It turns out that I should use the javac -cp .;json-simple-1.1.1.jar C:\Users\yiges\Desktop\COMP90015\Project3\WhiteBoard\src\Main.java command to compile the code
Problem is that - I have a program that builds and runs fine. It is written in Scala and it uses the Kafka Streams DSL. I was to use the new kafka-streams-scala package and I am using Maven right now. I can't use SBT right now. When I add the dependency
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams-scala_2.11</artifactId>
<version>2.0.0</version>
</dependency>
I then get all kinds of errors in the code, that already runs. I can't even do the following import statement
import scala.collection.JavaConverters._.
When I do, I get the following error
object language is not a member of package org.apache.kafka.streams.scala.
Why is this happeneing and how can I fix it?
I needed to prefix _root_ to all the Scala core packages like for example
import _root_.scala.collection.JavaConverters._
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.
I'm really a beginner with ant, anyway I'm working with a java project built with ant.
There're, simplifying, two projects imported in Eclipse:
The project1 contains the class1 with the methods1, methods2 and methods3.
In project2 there's a class2 that call the class1.method3().
The ivy.xml on project2 contains:
<dependencies>
<dependency org="my.package"
name="project1"
rev="latest.${project.version.status}"
conf="default">
<exclude module="servlet-api"/>
</dependency>
</dependencies>
The issue is:
The method method3() is undefined for the type class1
(line 53 class2.java)
I've tried several combinations, my "favourite" is:
With terminal in project1 folder:
ant clean-lib lib
ant publish-local
And in project2 folder:
ant clean-lib lib
Refresh, clean and build all projects in Eclipse
But it doesn't works, so... how can I update the project1.jar referred by project2? What am I doing wrong?
Thanks
The subtleties of latest.[version] are lost on me, but if you're always going to be picking the newest, then you might as well do latest.integration.
(Also according to here, it looks like what you were doing is syntactically correct, so maybe project.version.status wasn't a proper value)
For some reason my Intellij IDEA IDE started highlighting the use of anything from outside the local class as an error. It only does it for items in the packages I wrote - for example, packages like java.* do not show as errors. Even the joda-time dependency has no error highlights, it's just from my own packages. The problem only started occuring after I wrote a pom.xml for the project, so I'm assuming it has something to do with maven.
For example, the main of the following line is red with the error cannot resolve symbol 'main':
import main.java.com.jamobox.jamchatserver.clients.ClientReader;
Then in instances where a class is given as a parameter, e.g.
public void doSomething(Client c) { .. }
and I put something like
doSomething(new Client());
It will highlight the value in the parameters in red saying
doSomething(Client) cannot be applied to doSomething(main.java.com.jamobox.jamchatserver.clients.Client)
As I said the code compiles and runs absolutely fine, its just the IDE that thinks something is wrong. I have tried pretty much all of the answers given in this similar question, but nothing seems to have worked.
Anyone have any ideas on how to fix this?
In case it helps anyone figure this out, here is my current pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jamobox.jamchatserver</groupId>
<artifactId>JamChatServer</artifactId>
<name>JamChat Server</name>
<version>0.2.1</version>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
<type>jar</type>
<optional>false</optional>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When you say "it compiles fine", you do not indicate how you are compiling? Based on what you are describing, and what I suspect the issue is, I'm assuming you are compiling via maven.
It appears as if there is some mismatch in the declared source directory and the package names. When you create a (bare-bones) java project through IDEA, it makes the source directory {project.basedir}/src. Notice in the project view, the src directory is blue indicating it is a main (i.e. production) source directory:
This is also shown in the project structure dialog:
For a maven project, the default main (i.e.production) source directory is java in the path {project.basedir}/src/main/java. There is then a corresponding test source directory {project.basedir}/src/test/java. IDEA marks test source directories as green folders. Finally, there are both main and test resources directories that are used for things like configuration files, images, etc. In IDEA 12.x resources directories were marked as source and test-source directories with the same color as the corresponding java directory. In IDEA 13 (currently in beta and to be released in December) they are marked as distinct resource directories.
It sounds like when you converted to maven, the main\java directory was added to the src directory and the com root package directory was moved to java, but when this happened, the package declarations where changed from com.jamobox... to main.java.com.janbobox.... This likely happened because when you made the move, src was still configured as the source directory. So IDEA saw the package name change from com.jamobox... to main.java.com.janbobox... and change import statements (and likely package statements) to match.
To fix, you need to do the following:
Force import the maven pom using the "Reimport All Maven Projects" button in the Maven tool window (on the right side by default)
If the POM is not yet showing, click the add button , navigate to the pom.xml file and add it. Then run the reimport.
Verify the java directory (and not the src directory) is marked as the project source as shown in the above screenshot (showing both IDEA 12.x and 13.x project trees)
If the proper directories are not marked, try a reimport 2 or 3 more times. If that does not fix it (it should), go into File > Project Structure > [Modules] > [Sources Tab] and manually configure the proper sources. Remove any extraneous ones.
Verify that the com root package directory is in src\main\java and not src
Search and replace any package main.java.com strings with package com
Search and replace any import main.java.com strings with import com
That should fix the issues. If there is still red, run File > Invalidate Caches and restart IDEA. If after that there are still issues, please edit your original question and add screenshots of your project tree and the File > Project Structure > [Modules] > [Sources Tab] dialog window.