how to build jar file from my project?
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\sr开发者_C百科c\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
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>
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!
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.
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".
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.
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>
精彩评论