i wanted to practice developing database programs in java so i set the classpath to E:\software\installed\java\jre\lib by declaring a new environmental variable classpath and gave value as E:\software\installed\java\jre\lib but now i am unable to run any program(not even non-database) i get an error
Error: Could not find or load main class MysqlConnect
but when i delete the classpath variable i am able to run non-database programs. what is the possible problem and please let me know the solution. i have set path to E:\software\installed\java\bin
nothing is helping i tried using class path switch in java which is not helping (java -cp C:\Program Files\MySQL\MySQL Server 5.5 MysqlConnect) nor do setting path is helping (set CLASSPATH=%CLASSPATH%:C:\Program Files\MySQL\MySQL Server 5.5:C:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar) all are giving the error
Error: Could not find or load main class MysqlConnect
You shouldn't be defining a classpath for your programs using system variables. Standard way is to use the command line -cp or -classpath option. Take a look at what java prints out if you run it with no arguments.
You will find this mentioned in this tutorial. It says:
The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care
Also, see how the default CLASSPATH environmetn variable has a . in it. If you still decide to add your classes in there, keep the . for other citizens and add your classes after a ;, don't just overwrite the whole value.
Here's a jdbc tutorial for beginners that could help you find your answer. If you skip to step 14 it gives an example of how the classpath is used. It is used as the first respondent is saying, by command line.
Hopefully this will help you in your particular situation. This tutorial is not database-specific so it will work with any type of database you are using.
ok atlast i got the solution it should be typed as
C:\Users\sarad mohanan\Desktop\rose>java -cp .;"c:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar" MysqlConnect
MySQL Connect Example.
Connected to the database
Disconnected from database
we have to add .; before the original path . holds default classpath. pravel veller had said it previously but i didn't understand it then
I would like to propose using a good tool like Eclipse. You can test the CLASSPATH indirectly and your environment by adding or removing jar files and libraries.
Obviously, the libraries in your default CLASSPATH is different than the one in your E drive. You may compare the files by knowing your CLASSPATH. In Windows, do "echo %CLASSPATH%".
Eclipse can help you by experimenting without rebooting or any annoying steps. And this stuff is not easy.
Crete o set environment variable if you use windows JAVA_HOME=E:\software\installed\java, and after append the Java bin directory %JAVA_HOME%\bin. Note that paths are separated from each other with semicolons (;) I hope help you. That's work for me !!!. I don't understand. What happen?.
Related
I am trying to install log4j (2) on Windows 10. I downloaded and extracted log4j from https://logging.apache.org/log4j/1.2/download.html
However I don't know what do add to the path variable or how to call log4j on windows 10.
The latest steps on Linux for log4j where:
$ export CLASSPATH=$CLASSPATH:/usr/local/apache-log4j-1.2.15/log4j-1.2.15.jar
$ export PATH=$PATH:/usr/local/apache-log4j-1.2.15/
The Problem here is, as far as I know, Windows has no classpath and there is no log4j.jar file just log4j-core and log4j-api (and similar) jars.
If someone could help me set this up correctly I'd greatly appreciate this.
Log4j does not require installation. It is a set of libraries. You should not specify the CLASSPATH as a system-wide environment variable (however it is acceptable). If you want your application make use of log4j you should propagate the class path to log4j libraries as a parameter to java.exe. If you need those libs on development phase you should either specify the path in your IDE project settings (the way how to do this is specific for each particular IDE), or, if you use standard maven project type, specify the appropriate dependency in pom file so that IDE takes care of proper classpath configuration.
Please also refer to this post helping you to get started with log4j.
I have been struggling to understand where Maven (version 3.1.1) looks for the local settings.xml file on Windows 7. Can someone please explain what Maven is doing as it logs the below lines during the execution of any mvn command with the -X switch?
[DEBUG] Reading user settings from ???
Is it examining an environment variable to construct the path? If so, which one? I'm asking this because I was greatly surprised to see that it was examining the path
\\computername\userName\.m2\settings.xml
instead of the expected location on my C drive, which is
C:\Users\userName\.m2\settings.xml
As Tunaki has pointed out, Maven uses the Java system property ${user.home}, which does not always resolve to path that we might expect it to.
To force ${user.home} to be a different path, I had to add the environment variable "_JAVA_OPTIONS" and give it the value "-Duser.home=%UserProfile%", which is the path I thought it should have been looking in the whole time.
The Spring Boot Maven and Gradle plugins can now generate full executable archives for Linux/Unix operating systems.Running a fully executable JAR is as easy as typing:
$ ./myapp.jar
My question is in this case how to set -D properties, e.g.
-Dspring.profiles.active=test
In addition, if server does not install jdk , could this fully executable jar still run?
There are two ways to configure properties like that:
1:
By specifying them in a separate configuration file. Spring Boot will look for a file named like JARfilename.conf which should be stored in the same folder like the JAR file. There you can add the environment variable JAVA_OPTS:
JAVA_OPTS="-Dpropertykey=propvalue"
2:
Or you can just specify the value for the environment variable in the shell before you execute the application:
JAVA_OPTS="-Dpropertykey=propvalue" ./myapp.jar
Have a look at the documentation for the complete list of available variables: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-service
Regarding your second question: To execute a JAR, you don't need a JDK, a JRE is sufficient (but you need at least that, if you don't have any java installed on the server, the application won't run).
By default SpringApplication will convert any command line option arguments (starting with ‘--’, e.g. --server.port=9000) to a property and add it to the Spring Environment. As mentioned above, command line properties always take precedence over other property sources.
e.g.
$ java -jar myapp.jar --spring.application.json='{"foo":"bar"}'
please see http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/
well, there are so many threads discussed about this topic , but unfortunately nothing worked for me .
I am sending username/pwd to the server and server is interacting with JDBC client . this is my goal .
but I am getting above mentioned error while executing the below piece of code
ERROR: Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
CLASSPATH varaible here :
C:\ProgramFiles\Java\jdk1.7.0_17\bin;C:\ProgramFiles\Java\jdk1.7.0_17\db\lib;C:\ProgramFiles\Java\jdk1.7.0_17\db\lib\derbyclient.jar;
I'm pretty sure this jar contains ClientDriver.class .
I dont know where I did mistake .. anyone pls help me .
The CLASSPATH environment variable is almost never used. Make sure the 'derbyclient.jar' is on the actual classpath of your application.
If running from the IDE: make sure it is on the IDE build path of your application
If running with java -jar ... make sure it is in the Class-path attribute of the META-INF/MANIFEST.MF
If running with java -cp ... make sure it is in the -cp list.
Also if you are using a JDBC 4 compliant driver, you don't need to call Class.forName("org.apache.derby.jdbc.ClientDriver"), calling newInstance() is never necessary to load the driver (unless you are using Java 1.0 or 1.1 which you aren't).
You must add derbyclient.jar to YourProject\WebContent\WEB-INF\lib. Not needed to add derby.jar to classpath.
It's helped me.
I also need to generate outside eclipse and i didn't figured out how to do it.
I've read this thread but I have another problem to overcome first : I'm unable to start the main !
I tried different ways : export the project as standalone, put the project in a regular or executable jar, and launch directly Generator.class. I would like some help with the last solution. Here's how I launch it :
java -cp "..\testGene\bin\;C:\Program Files\Eclipse\plugins" testGene.main.Generate testModel.uml outputDir
I can't copy the whole console (dev computers are not connected to internet), but it says :
Exception in thread "main" java.lang.NoClassDefFoundError: org/Eclipse/acceleo/engine/service/AbstractAcceleoGenerator
Could not find the main class: testGene.main.Generate.
The generator works well inside eclipse, and I manage to call a simple test class with the same command line. I tried to copy the whole acceleo plugins in my bin directory in case the space in "Program Files" is a problem.
I'm pretty sure this is a simple error I made, any ideas ?
Furthermore, I'm not sure that it's sufficient to use the plugins folder in your classpath. Shouldn't there be a list of the jar files you need?
Since the program does not seem to find the AbstractAcceleoGenerator I would say that you are lacking some dependencies of the generator. Have a look at this screenshot to see the jar used for an UML to Java generator.