`

java jar getResource() null exception

    博客分类:
  • java
 
阅读更多

    1. Adding resource folder to classpath:

    When you Clean-&-Build a NetBeans Ant Based Project it creates a manifest.mf file in the root directory of the project. This file gets included in the JAR file also. Modify this file and add entry like follows:

    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    Class-Path: arts/ 

    slash is important after arts in the class path.

    Including the arts resource folder in the distribution

    Either copy this folder in the dist folder after the build or add a ANT target to copy the required resources in the dist folder.

    2. Add the target like as follows in the build.xml file:

    <target name="-post-jar">
         <mkdir dir="${dist.dir}/resources"/>
         <copy todir="${dist.dir}/resources">
             <fileset dir="${basedir}/resources" />
         </copy>
     </target>

    3. Code to access such resources:

    The code needed to access such resource files shall be as follows: (This will not work in design time but surely from the JAR file)

    // pay attention to relative path
    URL resource = ClassLoader.getSystemResource("gui/refresh.png");
    ImageIcon tmp = new ImageIcon(resource);

    NOTE: The files manifest.mf and build.xml located in the root directory of the project are accessible from the Files Panel in NetBeans IDE

分享到:
评论

相关推荐

    java操作redis所需jar包.zip

    try (Jedis jedis = pool.getResource()) { jedis.set("key", "value"); String value = jedis.get("key"); System.out.println(value); } catch (Exception e) { e.printStackTrace(); } finally { // 关闭...

    在Java程序前添加一个闪屏

    如果闪屏图片在JAR内部,你需要使用`Class.getResource()`或`Class.getResourceAsStream()`来获取图片资源。 ```java ImageIcon icon = new ImageIcon(this.getClass().getResource("/splash.png")); ``` 4. **...

    Redis的Jar包和工具类.rar

    return pool.getResource(); } public static void returnResource(Jedis jedis) { jedis.close(); } // 示例:设置键值 public static void set(String key, String value) { try (Jedis jedis = get...

    java读取资源文件

    - 使用`Class.getResource()`或`Class.getResourceAsStream()`方法: - `getResource()`返回一个`URL`对象,适合处理网络或磁盘上的资源。 - `getResourceAsStream()`返回一个`InputStream`,适用于读取二进制...

    java皮肤包

    URL resource = classLoader.getResource("path/to/your/lookandfeel.jar"); if (resource != null) { File skinFile = new File(resource.toURI()); System.setProperty("jnlp.jar", skinFile.getAbsolutePath...

    JAVA实现Excel表数据导入ORACLE数据库

    首先,需要安装相关的JAR包,包括Oracle的JDBC驱动包、JXL包和Apache Commons DBUtils包。这些包将帮助我们连接到ORACLE数据库和读取Excel表中的数据。 在连接到ORACLE数据库之前,我们需要首先加载Oracle的JDBC...

    Java邮件开发Fundamentals of the JavaMail API

    For JavaMail 1.2 users, you should now have added mail.jar and activation.jar to your CLASSPATH. For JavaMail 1.1.3 users, you should now have added mail.jar, pop3.jar, and activation.jar to your ...

    IOUtils组件,搭配本文项目专用

    这段代码首先通过`Thread.currentThread().getContextClassLoader().getResource()`或`getResourceAsStream()`方法找到类路径下的资源,然后使用IOUtils的`toString()`方法将输入流转换为字符串,这样就能方便地读取...

    Tomcat6.0使用jdbc连接池连接mysql--操作步骤介绍.doc

    C:\Program Files\Java\jdk1.5.0_09\lib\mysql-connector-java-5.1.3-rc-bin.jar; CATALINA_HOME=c:\tomcat JAVA_HOME=C:\Program Files\Java\jdk1.5.0_09 ``` #### 三、部署 Web 服务 部署 Web 服务涉及到两个...

    springmybatis

    1. 在MyBatis 里面创建两个源码目录,分别为 src_user,test_src, 用如下方式建立,鼠标右键点击 JavaResource. 2. 设置mybatis 配置文件:Configuration.xml, 在src_user目录下建立此文件,内容如下: 程序代码 程序...

    oracle联接tomcat+jsp

    &lt;Resource name="jdbc/MyDB" auth="Container" type="javax.sql.DataSource" username="username" password="password" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@//localhost...

    MS-SqlServer2012版本的JDBC包和JAVAWeb连接配置文件(例子)

    在Java Web开发中,连接Microsoft SQL Server 2012数据库通常涉及到JDBC(Java Database Connectivity)驱动的使用。本文将详细介绍如何配置和使用MS SQL Server 2012的JDBC驱动,以及相关的JAVAWeb连接配置文件设置...

    tomcat数据源配置

    不同的版本可能需要不同的驱动文件,例如,这里提到的`mysql-connector-java-3.1.12-bin.jar`是用于连接MySQL的JDBC驱动,而`commons-dbcp-1.2.2.jar`和`commons-pool-1.3.jar`则是Apache Commons数据库连接池和对象...

    MyBatis Generator工具,存放桌面,方便快捷

    InputStream is = resourceLoader.getResource("classpath:generatorConfig.xml").getInputStream(); List&lt;String&gt; warnings = new ArrayList(); boolean overwrite = true; ConfigurationParser cp = new ...

    javaweb 配置Oracle10g 数据池

    public static Connection getConnection() throws Exception { Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup("java:/comp/env"); DataSource ds = ...

    Jsp连接SQL2005数据库

    对于SQL Server 2005,需要下载Microsoft的JDBC驱动(如sqljdbc4.jar)并将其添加到Tomcat的lib目录下,确保服务器可以访问。 **2. 数据库连接** 在JSP中,我们通常使用Java的`java.sql`包中的`DriverManager`类来...

Global site tag (gtag.js) - Google Analytics