2

I wrote a program with java and mysql and now i want to have a jar file that when i click on it the program work(without that mysql install on my system).

I right click on my project an pressed clean and build but it didn't build jar file and below

wrote in output.

Updating property file: C:\Users\mehdi\Documents\NetBeansProjects\project1\build\built-clean.properties
Deleting directory C:\Users\mehdi\Documents\NetBeansProjects\project1\build
clean:
init:
deps-jar:
Created dir: C:\Users\mehdi\Documents\NetBeansProjects\project1\build
Updating property file: C:\Users\mehdi\Documents\NetBeansProjects\project1\build\built-jar.properties
Created dir: C:\Users\mehdi\Documents\NetBeansProjects\project1\build\classes
Created dir: C:\Users\mehdi\Documents\NetBeansProjects\project1\build\empty
Compiling 8 source files to C:\Users\mehdi\Documents\NetBeansProjects\project1\build\classes
C:\Users\mehdi\Documents\NetBeansProjects\project1\src\project1\NewUser.java:24: package sun.swing.table does not exist
import sun.swing.table.DefaultTableCellHeaderRenderer;

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
C:\Users\mehdi\Documents\NetBeansProjects\project1\nbproject\build-impl.xml:595: The following error occurred while executing this line:
C:\Users\mehdi\Documents\NetBeansProjects\project1\nbproject\build-impl.xml:276: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

now i want to know how can i build a jar file from my program that work correct without that mysql installed.

I use net beans 6.9.1

and jdk-6u23-windows-i586
Mahdi_Nine
  • 14,205
  • 26
  • 82
  • 117

6 Answers6

2

I had the same problem. To make things work, I added this to the pom.xml file...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <compilerArguments>
            <bootclasspath>${java.home}\lib\rt.jar</bootclasspath>
        </compilerArguments>
    </ configuration>
</plugin>
Adrian Romanelli
  • 1,795
  • 16
  • 23
1

Actually there are 2 questions that I would like to separate: 1. How to overcome the compilation errors? 2. How to package your project into a standalone runnable jar file?

Enough was said above on the 1st one. I only want to add some general recommendation: carefully check your classpath before exporting your project: different IDEs may have diferrent libraries on the classpath set by default but when you export your code and run it from command line in some other location things stop working because the 3rd parties that were previously available are not available anymore.

Regarding the second question : you need to package all the 3rd parties you are using inside your jar. I am sure that there should be some NetBeans plugin that can help doing it.You may find this link helpfull:

http://dr.berkeley.edu/REM/wiki/index.php/Making_a_Java_executable_jar_in_Netbeans

Good luck!

aviad
  • 8,229
  • 9
  • 50
  • 98
0

Probably you have to add javac -XDignore.symbol.file while compiling, see Using internal sun classes with javac

Just for reference with maven it would be something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <compilerArgument>
            -XDignore.symbol.file
        </compilerArgument>
    </configuration>
</plugin>
Community
  • 1
  • 1
Jaime Hablutzel
  • 6,117
  • 5
  • 40
  • 57
0

It's got nothing to do with mysql at all. The error of compilation is clear:

C:\Users\mehdi\Documents\NetBeansProjects\project1\src\project1\NewUser.java:24: package sun.swing.table does not exist
import sun.swing.table.DefaultTableCellHeaderRenderer;

Your build failed because it couldn't find the import anywhere. Fix your imports and recompile again.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • @mehdi, That error log doesn't lie. It may run with NetBeans, fair enough, try and figure out why is it failing during compilation. – Buhake Sindi Apr 04 '11 at 16:50
  • 1
    @mehdi, The import is from the sun.* package, which generally you shouldn't use in your code. Do you have multiple JDKs installed? Perhaps it runs correctly with Netbeans because it is using a Sun JDK, but when you run it in this other method, you are using a non-Sun JDK, so the class does not exist. – wolfcastle Apr 04 '11 at 17:09
0

It wouldn't harm also to right-click your project and go Properties-->Build-->Compiling at the bottom fill the Additional Compiler Options with "-Xlint:deprecation".

Costis Aivalis
  • 13,680
  • 3
  • 46
  • 47
  • i fill the **additional compiler option** with **-Xlint:deprecation** but it didn't word. – Mahdi_Nine Apr 04 '11 at 16:53
  • You had these messages: 1. Note: Some input files use or override a deprecated API. and 2. Note: Recompile with -Xlint:deprecation for details. The compiler option resolves the second issue. You must try to find the deprecated API and get rid of it. In general Netbeans creates perfectly running jars if the input is right. – Costis Aivalis Apr 04 '11 at 18:15
0

I'm going to venture that you're trying to build with OpenJDK, which would not have the sun.* packages. It may run in netbeans because of Netbeans continuous compilation. Check your settings to ensure that you're using the sun JDK and things should then work.

Varun Madiath
  • 3,152
  • 4
  • 30
  • 46
  • or avoid using the sun.* packages! – Riccardo Cossu Apr 04 '11 at 17:56
  • I'd normally suggest it, but that would presume that he was using them without any real reason to. There are occasions when it may be necessary to use the sun packages. I had to do that when using the javax.sound apis for example. – Varun Madiath Apr 04 '11 at 18:13
  • I agree, I just wanna point out that if someone is using sun.* packages should be very sure about the reason he's doing that, and not use them by accident (because eclipse suggested it for example!) – Riccardo Cossu Apr 05 '11 at 07:44