Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:15:15+00:00 2026-06-15T05:15:15+00:00

I am using sbt for a simple, small GUI projects that load icons from

  • 0

I am using sbt for a simple, small GUI projects that load icons from src/main/scala/resources. At first, everything works fine and I can compile. package, and run. The generated jar and class files all have the resource folder in it. Then I do the clean command. I re-run the compile and package, and suddently the application crashes. I check the generated jars and classes, and found out that the resources folder are not copied this time.

Running the application now gives me the NullPointerException pointing to the line where I load the resource (icon).

I didn’t change the sbt build files or anything in the project. Just run clean and re-run compile and package. I don’t know where to start looking for the problem. Where should I start looking? What am I doing wrong?

EDIT (the minimal example)

The project is a standard Scala template from typesafe’s g8 (https://github.com/typesafehub/scala-sbt.g8). Here’s my Build.Scala:

import sbt._
import sbt.Keys._

object ObdscanScalaBuild extends Build {
  val scalaVer = "2.9.2"

  lazy val obdscanScala = Project(
    id = "obdscan-scala",
    base = file("."),
    settings = Project.defaultSettings ++ Seq(
      name := "project name",
      organization := "thesis.bert",
      version := "0.1-SNAPSHOT",
      scalaVersion := scalaVer,
      // add other settings here

      // resolvers

      // dependencies
      libraryDependencies ++= Seq (
        "org.scala-lang" % "scala-swing" % scalaVer,
        "org.rxtx" % "rxtx" % "2.1.7"
      )
    )
  )
}

It builds the code fine previously. Here’s the project code directory structure:

enter image description here

It works fine and output this directory inside the jar at first:

enter image description here

And suddently, when I do a clean and compile command via the sbt console, it didn’t copy the resource directory in the jar or in the class directory (inside target) anymore. I can’t do anything to get the resource directory copied to target now, except by restoring previous version and compile it one more time. I restore the previous version via Windows’ history backup.

Is it clear enough? Anything I need to add?

EDIT:

After moving the files to src/main/resources, the compiled files now contains the resources. But now, I can’t run it in eclipse. Here’s my code:

object ControlPanelContent {
  val IconPath = "/icons/"
  val DefaultIcon = getClass.getResource(getIconPath("icon"))

  def getImage(name: String) = {
    getClass.getResource(getIconPath(name))
  }

  def getIconPath(name: String) = {
    IconPath + name + ".png"
  }
}

case class ControlPanelContent(title: String, iconName: String) extends FlowPanel {
  name = title
  val icon: ImageIcon = createIcon(iconName, 64)

  val pageTitle = new Label(title)

  protected def createIcon(name: String, size: Int): ImageIcon = {
    val path: Option[URL] = Option(ControlPanelContent.getImage(name))

    val img: java.awt.Image = path match {
      case Some(exists) => new ImageIcon(exists).getImage
      case _            => new ImageIcon(ControlPanelContent.DefaultIcon).getImage
    }
    val resizedImg = img.getScaledInstance(size, size, Image.SCALE_SMOOTH)
    new ImageIcon(resizedImg)
  }
}

The TLDR version is this, I guess:

getClass.getResource("/icons/icon.png")

which works if I call from sbt console command. Here’s the result when I call the code from sbt console:

scala> getClass.getResource("/icons/icon.png")
res0: java.net.URL = file:/project/path/target/scala-2.9.2/classes/icons/icon.png

which when runned gives the following exception:

Caused by: java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at thesis.bert.gui.ControlPanelContent.createIcon(ControlPanel.scala:54)
    at thesis.bert.gui.ControlPanelContent.<init>(ControlPanel.scala:33)
    at thesis.bert.gui.controls.DTC$.<init>(Diagnostics.scala:283)
    at thesis.bert.gui.controls.DTC$.<clinit>(Diagnostics.scala)
    ... 60 more

EDIT 2: It works now. I just deleted the project from eclipse, re-run sbt eclipse and it magically works. Not sure why (maybe caching?).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:15:16+00:00Added an answer on June 15, 2026 at 5:15 am

    The SBT convention for resources is to put them in src/main/resources/, not src/main/scala/resources/. Try moving your resources folder up one level. Its content should then be included, meaning that you will get icons and indicator folders inside the generated jar file (directly at the root level, not inside a resources folder).

    If you put the resources in scala, I think it copies only the files that are compiled (i.e. .class files resulting from scala compilation).

    If it doesn’t solve your problem, can you post the lines of code you use to load the resource?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SBT scala application that runs fine using sbt run. However, this
I'm setting up the dependencies for my first Scala project using SBT. This is
I am new and had built some simple Scala applications / tutorials using SBT.
I'm developing a simple SBT project that includes InputTasks for benchmarking Scala Parallel collections.
I'm building a few Java-only projects using simple-build-tool. When I publish the artifacts from
I'm new to Scala, SBT and Specs. I have created a simple specification using
I'm using sbt 0.10 with Scala 2.9.1. I've read http://groups.google.com/group/simple-build-tool/browse_thread/thread/792e5360877e78/987b6af687b8e33b?lnk=gst&q=collect+jars#987b6af687b8e33b However I don't want
I'm currently working on a Scala project, that is using SBT, and I'm trying
I am using SBT as my build tool for building a Scala project. My
I'm starting with Scala + Android (and using the sbt android plugin). I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.