简体   繁体   中英

How can I attach and read the source code of Weka in my IDE?

i want to write some new java code on my IDE about weka, and i also want to use all source codes of weka. I open weka-src.jar file but i cannot see the inside of Eclipse or Netbeans.

How can i add all source code on my IDE? i saw this site: https://svn.cms.waikato.ac.nz/svn/weka/tags/dev-3-5-8/weka/ . However, i think i have to download one by one on this site. I know it is very simple but i didn't find any information on the internet. It is all about using some weka libraries on java.

That's a very good question and it deserves a solid answer. I'll try to give you one for the Eclipse IDE.

Preparing a Weka project via Maven

Create a new folder somewhere in your dev workspace: weka-sample . Next, within this folder, open a text editor (eg, TextEdit ) and create a file named pom.xml . Insert this content to the file and save it afterwards:

<?xml version="1.0" encoding="UTF-8"?>
<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.sample</groupId> <!-- Change it: your project or company-->
    <artifactId>weka-sample</artifactId> <!-- Change it: your project name-->
    <version>0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source> <!-- For Java 11: use "11"-->
        <maven.compiler.target>1.8</maven.compiler.target> <!-- For Java 11: use "11"-->

        <weka.version>3.8.3</weka.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>nz.ac.waikato.cms.weka</groupId>
            <artifactId>weka-stable</artifactId>
            <version>${weka.version}</version>
        </dependency>
    </dependencies>
</project>

Environment & project import

Make sure you've installed a recent Eclipse IDE (2018-12) . If this is present on your machine, continue with:

  1. Start Eclipse
  2. Click File > Import...
  3. Type Maven in the search box
  4. Select Existing Maven Projects
  5. Click Next
  6. Click Browse and select the folder that contains the pom.xml file
  7. Click Finish

If all of these steps worked, you will see a screen similar as below. Now, right click on the top-level of the project and click "Update Project". Make sure, your machine is connected to the Internet as the build tool (Maven) will now download several libraries from the central Maven repositories; most important: the latest version of the weka-stable artifact (3.8.x).

Weka样本更新Maven项目

Attaching the Weka source(s) & Finishing

We're almost done here. However, one important step remains.

  • Right click on the top level of the project again, select Maven , and click Download Sources .

  • In the background, Eclipse will now download several source artefacts for you and link them correctly to the libraries you'll find below the Maven Dependencies entry of the project (see screenshot above). Just click on it and you'll see several jar files, among them: weka-stable-3.8.3.jar

Finally

  • Create new folders src/main/java and src/test/java and add these to the Build-Path of the project. I'm assuming that you are familiar with this step. Note: The aforementioned directories comply with the standard layout in Maven projects . I'd recommend, you configure it like this in your Weka and other future projects.

  • Add your own source files to src/main/java . If you now click on one of the classes imported from the weka package... taaaadaaaa! You should now see the corresponding source code in the editor window of the IDE!

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM