Hello I am using IntelliJ Idea 13.0.1 and I downloaded the seaGlass LAF. The website instructed me to put it into my classpath but I have no idea where that is on my windows machine. I am not using a special package or anything. I'm just using the src folder and I tried putting the JAR file everywhere. No working. Can I get some help please. A SIMPLE classpath explanation would be good too.
By adding dependencies in IntelliJ you are in turn configuring the classpath of your application.
Create a java project in IntelliJ
Open the Project Structure | Module Dependency
Add your jar for seaglass LAF to the dependency list in the dialog
Add your java code to the project
Add the code for applying the seaglass LAF to your program
As you start your application the IDE will generate the java execution with the appropriate classpath. This classpath is created from the list of dependencies, one of which is your LAF. You can inspect the java program execution with the classpath parameter in the console output in the lower window in the IDE.
There are much better places than here to learn about what a classpath is.
Related
I created a javafx application via the IDE IntelliJ IDEA on ArchLinux. Now, I want to start this program without any IDE, so I created a .jar file. When trying to start the program with java -jar myprogram.jar, then I get the error message that runtime components for javafx are missing. Fine - I'll add these with the --module-path option, and it runs.
However, this --module-path thing only works somehow when I set the module path being somewhere in /lib/... On the other hand, when I try to copy the javafx modules into the folder where the myprogram.jar file is and set the module path there, the modules cannot be found.
My issue is the fact that I want to "self-contain" everything possible in one folder, such that I could copy&paste everything on another machine where the JVM is installed and just run it, and do not want to depend on the specific path where the javafx modules are installed. Maybe there is another way than to customize the --module-path?
Any help? Thanks :-)
Forget about trying to create a single executable jar that includes JavaFX components and depends on a pre-installed JVM (it is not a supported configuration).
However, cwellm's answer here details a method that keeps the modular JavaFX dependencies separate from the created application jar by keeping the JavaFX modules in separate jars added to the module path, I believe that this might be a valid and supported deployment configuration. It does require deploying multiple jar files to the client in the right locations in order for it to work. Another alternative would be to assume a distribution of the JDK such as liberica or corretto which can come with JavaFX included in the base JDK distribution, then you don't need to specify a module path for JavaFX as it will already be present in the default boot module path for the JDK.
Recommended Solutions
Instead create a runtime image using jlink, this can be done by (among other methods) using the openjfx maven plugin.
Or if you want an installer, use jpackage which can also (among other methods) be created using maven, see JPackageScriptFX as an example.
jpackage doesn’t create archlinux native packages. So if you want that, then jpackage wouldn’t be the thing to use. Instead you could use a maven assembly or tar call to create a zip or tar.gz of the jlink output, or use the pacman tool to create a native archlinux package of the same.
Or if you like gradle see the badass jlink and runtime plugins.
Using a build tool (maven or gradle) to include the JavaFX dependencies rather than relying a JavaFX sdk download is preferred IMO. Also, if possible, define a module-info. Then jlink can be used to create the required runtime from your app, it’s dependencies and the jre, as well as the execution script for the app, so that things are self-contained. Native packages in rpm or deb format created by jpackage takes this further. Installing apps packaged this way also ensures all required OS lib dependencies are correct.
If you want to understand more see the contextual info (FAQ section) in this answer:
How to create a standalone .exe in Java (that runs without an installer and a JRE)
It is possible to put several custom module paths into the command --module-path. It is important to really put in the full path of the required modules, including the filename of the module itself. For instance, let's assume I want to include the modules module1.jar and module2.jar for the execution of MyApplication.jar, and all of these files are put into the same folder, say /my/custom/folder. Then the command line command would look like this:
java -jar --module-path /my/custom/folder/module1.jar:/my/custom/folder/module2.jar --add-modules module1,module2 MyApplication.jar
I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.
I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.
I'm trying to include a weka-src.jar file in Netbeans project and use it.
I already have set up my CLASSPATH and included :
C:\Program Files\Java\jre6\lib\ext\weka-src.jar into it
My JAVA_HOME variable is set to:
C:\Program Files\Java\jdk1.6.0_25\bin
but still I get the error in Netbeans: package doesn't exist and NetBeans doesn't auto-complete when I'm trying to add it to imports
Similar to this I jave a jar file
C:\Program Files\Java\jre6\lib\ext\mysql-connector-java-5.0.8-bin.jar
also included in CLASSPATH and after adding to project Netbeans does the auto-complete thing.
My cmd:
echo %CLASSPATH%:
.;C:\Program Files\Java\jre6\lib\ext\mysql-connector-java-5.0.8-bin.jar;C:\Program Files\Java\jre6\lib\ext\weka-src.jar
Tried in Eclipse, the import part is not underlined, but still I can't use the classes, as if weka-src.jar wasn't even added
I can't figure out what is wrong. Any hints, please?
Maybe there is someone who can test it in his environment? weka-src.jar is in Weka's program files folder.
I am guessing that weka-src.jar contains source code which need to be compiled before it can be used. Perhaps there is a weka.jar which has the compiled classes in it.
In netbeans, you don't make classpath with windows environments variables, but with netbeans.
In netbeans right clic on your project node in window projects, choose Properties, and in properties Librairies. Add your jar.project/librairies with that.
Istao is correct. For NB you need to add jars via Properties
I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.