H2 driver not found when try to connect - classpath

I have gone through some other answers, but cannot get the solution to my problem.
I am using NetBeans 7.0.1 and the latest version of the H2 DB on Win7.
I successfully use the H2 console tool and I have also added the driver in NetBeans and am able to connect (i.e. see the DB, tables, issue commands, etc). However from within my Java code when running it, I get the message: "java.lang.ClassNotFoundException:org.h2.Driver".
My code is:
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/testDB", "sa", "");
Statement query = null;
query = conn.createStatement();
String firstString = "INSERT INTO ......";
query.executeUpdate(firstString);
I have also added the H2 jar file in the classpath (although I had to create the classpath myself and point to the jar file) - I went to environment variables -> user variables
name=classpath value=.;C:\NetBeansProjects\testdemo\src\testdemo\DB\h2-1.3.165.jar
What am I doing wrong?

Add the H2 jar file in the "Libraries" section under the source code packages.

Change parent version
spring-boot-starter-parent
1.4.3.RELEASE

Related

How to change EclipseLink in GlashFish 4.0?

I want to change EclipseLink from 2.5.0 to 2.5.1 in GlashFish 4.0. I have downloaded the OSGi bundle and replaced the following jar files
org.eclipse.persistence.antlr.jar
org.eclipse.persistence.jpa.jar
org.eclipse.persistence.asm.jar
org.eclipse.persistence.jpa.modelgen.jar
org.eclipse.persistence.core.jar
org.eclipse.persistence.oracle.jar
javax.persistence.jar
under $GLASSFISH_HOME/glassfish/modules.
After doing this, the version still remains the same. The following code,
String version = org.eclipse.persistence.Version.getVersion();
System.out.println("EclipseLink version : " + version);
still displays the version 2.5.0.
The bundle contains no eclipselink-x.x.x.jar.
What else is required to be changed? I'm using NetBeans 7.2.1.
You forgot some files, you need the complete list:
org.eclipse.persistence.antlr.jar
org.eclipse.persistence.asm.jar
org.eclipse.persistence.core.jar
org.eclipse.persistence.dbws.jar
org.eclipse.persistence.jpa.jpql.jar
org.eclipse.persistence.jpa.jar
org.eclipse.persistence.jpa.modelgen.jar
org.eclipse.persistence.moxy.jar
org.eclipse.persistence.oracle.jar
javax.persistence.jar
You don't have to rename the files, you can delete the old files starting with org.eclipse and copy the required files to the modules folder.
This should do the trick.
Update: If it doesn't work you may have to clear the OSGI cache. To do this shutdown the server and delete the folder felix in
$GLASSFISH_HOME/glassfish/domains/domain/osgi-cache/
Restart the server and wait a moment, it'll have to read the OSGI module information to rebuild the cache.

Use webapp classpath using JavaCompiler in Tomcat within Eclipse with Maven

I have an existing "Example Webapp" that references "Example Library" using Maven. I'm running Tomcat 7 inside Eclipse 4.3RC3 with the m2e plugin. When I launch Example Webapp on Tomcat inside Eclipse, I have verified that the example-library.jar is probably getting deployed in the Tomcat instance's WEB-INF/lib folder.
The Example Webapp has code that compiles certain classes on the fly using JavaCompiler.CompilationTask. These dynamically generated classes reference classes in example-library.jar. Unfortunately the compile task is failing because the referenced classes cannot be found.
I understand that I can set the JavaCompiler classpath, but System.getProperty("java.class.path") only returns me the Tomcat classpath, not the webapp classpath:
C:\bin\tomcat\bin\bootstrap.jar;C:\bin\tomcat\bin\tomcat-juli.jar;C:\bin\jdk6\lib\tools.jar
Other have said that I need to get the real path of WEB-INF/lib from the servlet context, but the class generation code doesn't know anything about a servlet context --- it is written to be agnostic of whether it is used on the client or on the server.
In another question, one answer indicated I could enumerate the classloader URLs, and sure enough this provides me with the jars in WEB-INF/lib, but when I provide this as a -classpath option to compiler.getTask(), the task still fails because it can't find the referenced classes.
How can I simply provide the classpath of the currently executing code to the JavaCompiler instance so that it will find the classes from the libraries in WEB-INF/lib? (A similar question was raised but never answered regarding referencing jars within ear files using JavaCompiler.)
Example: In an attempt to get things working at any cost, I even tried to hard-code the classpath. For example, I have foobar.lib in my webapp lib directory, so I used the following code, modified from the answers I indicated above:
List<String> options = new ArrayList<String>();
options.add("-classpath");
options.add("C:\\work\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\FooBar\\WEB-INF\\lib\\foobar.jar");
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
boolean success = task.call();
In the end success is false, and my diaognostics indicates package com.example.foo.bar does not exist..., even though that package is in foobar.jar.
Put example-library.jar somewhere in your file system and pass that location to the code that runs JavaCompiler (the -classpath option). If you use an exploded WAR file to deploy, you can of course point it to the physical location within the WEB-INF/lib folder. The point is that you only need one configurable parameter in your webapp to do this, which can be a properties file entry, -D system property, database row or something else entirely.
Sample code (tested in Tomcat 7 and OpenJDK 1.7 on Fedora 18 x64):
private File compile(File javaFile, String classpath) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjects(javaFile);
List<String> options = classpath != null ? Arrays.asList("-classpath", classpath) : null;
StringWriter output = new StringWriter();
try {
boolean successful = compiler.getTask(output, fileManager, null, options, null, compilationUnit).call();
if (!successful) {
throw new CompilationException("Failed to compile: " + javaFile, output.toString());
}
return firstClassFileFrom(javaFile.getParentFile());
} finally {
fileManager.close();
}
}
private File firstClassFileFrom(File directory) {
return directory.listFiles(new FilenameFilter() {
#Override
public boolean accept(File dir, String name) {
return name.endsWith(".class");
}
})[0];
}
See https://github.com/jpalomaki/compiler for a runnable sample webapp.
i met the same question. The reason is not "-classpath" .
my code :
String classpath ="xx/WEB-INF/clases ";
List<String> options = classpath != null ? Arrays.asList("-d", classpath,"-cp",classpath) : null;
CompilationTask task = compiler.getTask(null, javaDinamicoManager, diagnostics,
options, null, Arrays.asList(sourceObj));
boolean result = task.call();
the “result” will return true .
You could follow the answer provided for the even more specific question of how to load dependencies of compiled code from within a web app running directly from an unexpanded WAR file (there are no JAR files to reference - only the container's class loder knows how to access the classes): https://stackoverflow.com/a/45038007/2546679

ClassNotFoundException with PostgreSQL and JDBC

I am having some difficulty in making connectivity with Java and PostgreSQL Database.I have download the JDBC4 Postgresql Driver, Version 9.2-1002 driver and properly set the application ClassPath. My code is as under
import java.sql.*;
public class JavaPostGreSQLConnectivity
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect("jdbc:postgresql://127.0.0.1:5432/TestDB", "postgres","pwd");
}
}
class DB
{
public DB() {}
public void dbConnect(String db_connect_string, String db_userid, String db_password)
{
try
{
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
Upon running I am getting the below error
Is it complaining about
Class.forName("org.postgresql.Driver");
If so then what will be the driver name? However, I followed this for my learning purpose.
However, If I do
C:\Program Files (x86)\Java\jdk1.7.0\bin>java -cp C:\Users\pos
tgresql-9.2-1002.jdbc4.jar; JavaPostGreSQLConnectivity
connected
It works.Why I need to explicitly mention the driver again when I have already placed it in the classpath properly? Is there any alternative way (I just want to put the JAR file in Classpath and the program should read from there)?
Thanks in advance
The driver name is OK. It is the same as mentioned in the official docs of the driver. Therefore the driver is just not in the classpath.
You say:
I [...] properly set the application ClassPath
On the other hand you start the program by just calling:
java JavaPostGreSQLConnectivity
In that case no PG driver is on the classpath. You have to add it by hand using someting like
java -cp postgresql-jdbc4.jar JavaPostGreSQLConnectivity
EDIT The question has been changed while typing, hence the duplication.
You added the jar only in you IDE. This helps the IDE to compile your code. If you start the program using you IDE then the IDE will also set the classpath for you. But if you don't start via the IDE then nobody knows the correct classpath and it has to be set by hand.
Your options are:
start always via IDE
make some batch script which hides the setting of the classpath (common solution)
set the CLASSPATH environment variable (does not scale with other Java applications)
make an "Executable Jar" and set the classpath there. (Search this site using that term).
put the jar into a place where the JVM picks it up automatically (e.g. in the lib/ext directory of the JRE). But polluting the JRE/JDK libs is the worst option.
Note: This is all basic Java knowledge and has nothing to do with PostgreSQL.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 1: unable to resolve class

I am currently receiving this error when trying to run a soapui file:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Script7.groovy: 1: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1206)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148)
at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:585)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:472)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:292)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:141)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
1 error
soapUI code:
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
def env = testRunner.testCase.testSuite.project.getPropertyValue("env")
def baseUrl = testRunner.testCase.testSuite.project.getPropertyValue("baseUrl")
log.info("The baseurl is "+baseUrl)
log.info("The env under test is "+env)
SoapUI_T11001_StockConsSecurityCurBusiDate testStep = new SoapUI_T11001_StockConsSecurityCurBusiDate();
testStep.init(baseUrl);
testStep.execute(null);
eclipse code:
package com.company.ui.test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.eviware.soapui.model.support.AbstractSubmitContext;
import com.eviware.soapui.model.testsuite.TestRunner;
public class SoapUI_T11001_StockConsSecurityCurBusiDate extends BaseSelenium{
public static void main(final String[] args){
final SoapUI_T11001_StockConsSecurityCurBusiDate ico = new SoapUI_T11001_StockConsSecurityCurBusiDate();
try{
ico.init("https://avncedevn1.nam.nsroot.net:17620/", false);
}catch(Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
}
ico.execute(null);
}
//...code....
}
how do I solve this error ? I'm not sure what is causing the error.
This work for me:
Press Ctr+Alt+Shift+s
or:
From File menu -> Project Structure -> SDK Location -> JDK location Drop down menu choose:
Embeded JDK c:....\jre
Then ok.
If you using android studio and got this error then I solved it changing the Gradle version of the project to the newest version 6.2.1 on the project structure options.
One of the possible reasons is that the jdk version is too high. For example, using jdk 16 to build the source code of Apache Kafka throws this error. Using jdk 11 is fine.
bild.gradel file in change clashpath
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
}
gradel-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
I'm Using Android Studio - Arctic Fox and this worked for me
Go To File menu -> Project Structure -> SDK Location -> Gradle Setting
Then check the "Download external annotations for dependencies" button and select JDK location from the drop down menu and choose: Android Default Jdk Vesion.
Click on Ok.
If you wanted to make a new project on Android Studio after first install, probably you write your application name including (') sign as called apostrophe.
For Example, I tried to set a name as: "Henry's Game" but apostrophe caused Android Studio to not load because of this mistake:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
So, just change your application's name, and simply use Latin alphabet languages such as English.
To fix: Go to your Android Project Tree and find Gradle Scripts > settings.gradle > change the name:
rootProject.name='Henry Game'
include ':app'
With Eclipse Juno (Kepler Release) Build id: 20121114-2344, I found similar problem:
org.codehaus.groovy.control.multiplecompilationerrorsexception startup failed unable to resolve class Chart
The class Chart is my container class for some utilities for charting.
I tried outside of Eclipse, with Groovy 2.0 Console the same code segment works fine. After scratching my head for about 3 hours, I resolved it by adding the following
import excel.Chart
in the invoking class with main() that has "new Chart()" thus getting the complaints, once added, the error is gone. Even more weird, after passing the error, I remove that import, there is still no more complaints! (All my scripts/classes are under the same package excel, I suppose such import statement is not needed.)
One of the symptom of the complaints is that there was not Chart.class generated in the output bin folder. Once the complaints gone, Chart.class appeared there.
I guess that it might be a bug of Eclipse/Groovy plugin (I use Groovy Plugin for Juno).
Hope my understanding is correct, and it helps.
The solution for me was change the gradle version and the Gradle JDK:
File > Project Structure > Project
enter image description here
File > Project Structure > SDK Location
enter image description here
Go to Files and click Invalidate caches/ Restart . Android studio will clear the cached and it will be restarted without any error.
Hope this answer helps you :)
For this problem, you might also encounter package naming from gsp as I did. In the build/gsptmp folder, Grails 4.x.x creates temporary gsp files to link the classes that they refer to. Due to the change of a package name it was failing to do so in my case. Try with command grails war --stacktrace during war build!
Previously, it was <%# page import="bv.BankReconciliationController" %>
but the folder bv was renamed to factoring.
So, the solve was to change the import to
<%# page import="factoring.BankReconciliationController" %> and it worked :)
I have also faced the same and tried all of the solution here and other places as well, at last i deleted my .gradle and gradle both folder and caches of android studio and open the studio again and rebuild the project, it's works after that fine and used the latest gradle version and previously it was picking up the older version and causing issues.
for me , solution is to upgrade the gradle to latest version , and remove the .idea file , and invalidate caches and restart android studio.
When starting a project make sure to select SDK version 11 or later. It will default to a minimum SDK but you have to scroll down to a later version for it to work. Then the project should load and build.
For me, I just delete the .grade file under program files(C:\Users\username\ .gradle) in windows and it will work.
This work for me:
From File menu -> Project Structure -> SDK Location -> klik Gradle Setting for show hide menu, Gradle JDK choose:
Embeded JDK c:....\jre
Then ok.
Do you have the grail and groovy plugin installed? If so try uninstalling this plugin. I had the same error message and uninstalling the plugin, restart IDE worked for me.

Eclipse nodejs vjet v8 debugging

I am using Eclipse helios and I installed vjet and v8 debugging from the steps in the link below:-
http://jonathan-whywecanthavenicethings.blogspot.in/2011/08/war-of-worlds.html
Also, NodejsTL zip file i downloaded and set it in the build path of my project
But when i am trying to debug it in eclipse via. external tools configuration , I am getting below error:-
debugger listening on port 5858
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'E:\eclipse-jee-helios-SR1-win32\workspace\nodejswkspace\TempVjetProject\Server1.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
There's a pretty high chance that eclipse stuck it in a "src" or "source" folder when you set it up. As such the run configuration is basically assuming that your source folder deploys at root.
Double check the pathing and then try again. What I did was eliminate the source folder so I didn't have to deal with--alternatively do something like
--debug src/${resource_name}
//or better still since the above shouldn't work for subfolders...
--debug ${workspace_loc}/${resource_path}
I bet your path looks like:
E:\eclipse-jee-helios-SR1-win32\workspace\nodejswkspace\TempVjetProject\***src***\Server1.js
Here's what my project looks like now:
For my configuration this renders: