Eclipse/Hibernate tools error: Archive classpath entry doesn't exist - java

I am trying to setup Hibernate tools – attaching it to the spring petclinic project. So far the problem is in classpath. My actions:
Click on hibernate on the Hibernate Configuration view
Add
postgresql-9.1.jar located in the root directory of the
spring-petclinic project
The result is the error: [Classpath]: Archive classpath entry doesn't exist [/spring-petclinic/postgresql-9.1.jar] ( see http://jboston.net/HIbernateToolsError.jpg for the image)
See also the log:
java.lang.IllegalArgumentException: Path must include project and resource name: /postgresql-9.1.jar
java.lang.IllegalArgumentException: Path must include project and resource name: /postgresql-9.1.jar
at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2170)
at org.eclipse.core.internal.resources.Container.getFile(Container.java:208)
at org.hibernate.eclipse.console.utils.ProjectUtils.findJavaProjects(ProjectUtils.java:308)
at org.hibernate.eclipse.console.workbench.ProjectCompilerVersionChecker.validateProjectComplianceLevel(ProjectCompilerVersionChecker.java:35)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:37)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:100)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

#Craig Ringer answer helped. My workaround was as follows:
Create the user library with a postgresql jdbc jar
From the Hibernate configuration classpath tab select Advanced on the
right menu
Choose "Add library"

It looks like you've attempted to add the JDBC jar as a required project. Don't. Add it as a library dependency instead.
See this list of ways to do it - unverified, as I thankfully no longer have to use Eclipse anymore.

Related

Error occurred during initialization of boot layer - Eclips 2020-06

For running JTable in Java Swing at Eclips 2020-06, imported rs2xml.jar file. But after that, while running the program, the following error is occurring.
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for E:\Progrm Learning\JAVA\Student\rs2xml.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: JDOMAbout$Author.class found in top-level directory (unnamed package not allowed in module)
rs2xml.jar contains a class in the default package which is not allowed when using JPMS.
In Project > Properties: Java Build Path, tab Libraries move rs2xml.jar from the Modulepath to the Classpath and in the project, in the source folder, in the default package delete your module-info.java file to not use JPMS.
The answer provided by #howlger works but if after deleting your module-info.java file your
src file gives error then you could start a new project and while creating new project select don't create module-info
Nice question.
rs2xml.jar contains a class in the default package which is not allowed when using JPMS.
In Project > Properties: Java Build Path > Libraries, move rs2xml.jar from the Modulepath to the Classpath.
Then in the project, in the source folder, and in the default package delete your module-info.java file in order to not use JPMS.

Flyway can't find classpath:db/migrations

I just started right now a new project in Intellij using Spring Boot ver 2.1.3 and Flyway 5.2.4 with Java 11.
After try to start my project i got :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
I have the following folders:
As you can see i have "db/migration" but without any migration, i just started right now. Debugging the class FlywayAutoConfiguration i got the following:
So, i tried to return all files in "classpath:", see:
Note that i just have "application.properties" file.
It is not that much useful or accurate answer.
But This issue make you frustrated so that i give this solution.
Note: Strange but it's true, Sometime it's not allow copy paste because your folder created db.migration and it expact db->migration(It's not same in this scenario). So whenever you start from scratch. Go to the resource folder -> Create DB folder -> Create migration folder -> Create database file with Version_SubVersion__Name(As defined below).
Normally this happens in following cases,
Path is not proper try using set locations param value.
db.migrate folder not contain any file.
Check name of file : V1_1__(short_desc)
Try to run using, mvn compile flyway:migrate
In my case i already place sql file over there but still it gives same error,
Basically i place this sql file using copy paste from somewhere.
When i try to add one new file on same place using IDE (Intellij : Right click on migration folder -> new -> Flyway migration -> versioned migration), then it ask me(warning) about some delicate allowance(normally we mention in database configuration i also place there still), and it start working.
Flyway requires at-least one script, disable it until u need it by using following command in application.properties file
spring.flyway.enabled=false
I believe that Flyway requires at least one migration script to initialize. Try adding a simple sql creation script into your migration folder and give it another try. Alternatively you can disable the flyway dependency until you need it.
I had a similar error, and solved it as follows: I added these commands
spring.flyway.baselineOnMigrate=true
spring.flyway.check-location=true
spring.flyway.locations=classpath:db/migration
spring.flyway.schemas=public
spring.flyway.enabled=true
to application.properties
I had the same issue. When I created the directory, I simply typed db.migration - the same way one would do with package names. InteliJ will display both db.migration and db/migration directories as db.migration, so while it may look correct in IntelliJ, flyway requires the latter.
Even when having your migration files in the db/migration folder, flyway won't detect it.
Then you will have to fix this by explicitly setting the locations in your application.properties (or appliocation.yml) by adding:
spring.flyway.locations=classpath:db/migration
N.B: Also you need to have at least one script to initialize flyway, you can even put an empty one. But you need to have at least one script
As #Guy suggested in his answer, I created an SQL file in the migration folder and left it empty. Named v1_0__mock_flyway.sql in the migration folder classpath:db/migration. Error solved.
If you have tried everything above and it still does not apply the migrations.
Be sure you have followed the steps in the previous answers
A db.migration folder exists in your resources folder
The sql scripts are named with respect to the correct naming convention, such as V1__init.sql
The following config exists in your application.properties/application.yml
spring.flyway.locations=classpath:db/migration
Do a clean build
-> mvn clean
Then restart your spring boot app, this worked for me.

Apache Cayenne "DI container has no binding for key ObjectContextFactory" error

I'm using Apache 4.0 BETA and I'm getting the following runtime error:
org.apache.cayenne.di.DIRuntimeException: DI container has no binding for key <BindingKey: org.apache.cayenne.configuration.ObjectContextFactory>
at org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:158)
at org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:144)
at org.apache.cayenne.di.spi.DefaultInjector.getInstance(DefaultInjector.java:134)
at org.apache.cayenne.configuration.CayenneRuntime.newContext(CayenneRuntime.java:124)
As Cayenne is modular, I've included only these dependencies (see pic).
What library needs to be included?
Thanks!
(The backend db is postgres but I don't this this is relavant to this error.)
I resolved this problem myself. Turns out that I need to build the artifact with "copy to output directory and link via manifest" (using IntelliJ IDEA) and upload the entire generated _jar directory to the server.

Sonar properties files

I have a project that has the following package structure
src/main/proj
-com.company.package
-appName
-morepackages
-appVersion2
-morepackages
sonar-runner.properties
sonarBuild.sh
sonar-runner-project2.properties
sonarBuildProject2.sh
As it stands, with the default properties file i can run the sonar report and it will generate a review for the whole project
sonar.projectKey=KEY
sonar.projectName=PROJNAME
sonar.projectVersion=1.0
sonar.host.url=someurl
#Path for sonar sources
sonar.sources=src/main/java
#Path for libraries
sonar.libraries=target/lib/*.jar
#Path for binaries
sonar.binaries=target/classes
#--------Default database
sonar.jdbc.url=someurl
sonar.jdbc.driver=com.mysql.jdbc.Driver
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default directory layout
sonar.java.source=1.6
sonar.java.target=1.6
sonar.sourceEncoding=UTF-8
Ideally however I would like to separate the two reports so i have one for the original package and one for the appVersion2 package. Now - as mentioned above I have created a separate properties file for each. Should i just point sonar.sources to the respective packages for each job to analyse or is there a better way to do this all in one property file?
Thanks
EDIT
My multi module attempt properties file looks as follows
sonar.projectKey=rootkey
sonar.projectName=rootname
sonar.projectVersion=1.0
sonar.host.url=rooturl
sonar.sources=src/main/java/
sonar.libraries=target/lib/*.jar
sonar.modules=module1,module2
sonar.sourceEncoding=UTF-8
#----- Global database settings
sonar.jdbc.username=user
sonar.jdbc.password=pass
sonar.java.source=1.7
sonar.java.target=1.7
#--------Default database
sonar.jdbc.url=url
sonar.jdbc.driver=com.mysql.jdbc.Driver
module1.sonar.projectName=proja
module2.sonar.projectName=projb
module1.sonar.projectKey=projakey
module2.sonar.projectKey=projbkey
#Path for sonar sources
module1.sonar.sources=src/main/java/app1code
module2.sonar.sources=src/main/java/app2code
#Path for binaries
module1.sonar.binaries=target/classes/app1binaries
module2.sonar.binaries=target/classes/app2binaries
I get an error in the output saying....
Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: patthtoapp/module1
at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.runner.Main.execute(Main.java:84)
at org.sonar.runner.Main.main(Main.java:56)
Caused by: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: pathtoapp/module1
at org.sonar.runner.internal.batch.SonarProjectBuilder.setProjectBaseDir(SonarProjectBuilder.java:279)
at org.sonar.runner.internal.batch.SonarProjectBuilder.loadChildProject(SonarProjectBuilder.java:191)
at org.sonar.runner.internal.batch.SonarProjectBuilder.defineChildren(SonarProjectBuilder.java:169)
at org.sonar.runner.internal.batch.SonarProjectBuilder.generateProjectDefinition(SonarProjectBuilder.java:122)
at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.sonar.runner.Runner.delegateExecution(Runner.java:285)
You have to specify the projectBaseDir if the module name doesn't match you module directory.
Since both your module are located in ".", you can simply add the following to your sonar-project properties:
module1.sonar.projectBaseDir=.
module2.sonar.projectBaseDir=.
Sonar will handle your modules as components of the project:
EDIT
If both of your modules are located in the same source directory, define the same source folder for both and exclude the unwanted packages with sonar.exclusions:
module1.sonar.sources=src/main/java
module1.sonar.exclusions=app2code/**/*
module2.sonar.sources=src/main/java
module2.sonar.exclusions=app1code/**/*
More details about file exclusion
You can define a Multi-module project structure, then you can set the configuration for sonar in one properties file in the root folder of your project, (Way #1)
Do the build job on Jenkins first without Sonar configured. Then add Sonar, and run a build job again. Should fix the problem

Datanucleus RDBMS JPA jar-with-dependencues

I configured and I use Datanucleus JPA to connect to MySQL. I compile the classes and enhanced entities with datanucleus-enhancer-plugin. I can run my app using mvn exec:java and I can also run it after I create an archive with lib (jar dependencies).
The problem appears when I create a jar (jar-with-dependencies). I get this error:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "mysql" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl from provider: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at cantina.crawler.util.JpaUtil.getRdbmsEntityManager(JpaUtil.java:29)
at cantina.crawler.bolt.SiteDetectorBolt.prepare(SiteDetectorBolt.java:32)
at backtype.storm.daemon.executor$fn__4050$fn__4059.invoke(executor.clj:610)
at backtype.storm.util$async_loop$fn__465.invoke(util.clj:375)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.datanucleus.exceptions.NucleusException: Error creating handler of type "persistence" for metadata parsing : MetaData handler plugin "persistence" was not found. Please check your CLASSPATH and plugin specification.
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataStream(MetaDataParser.java:269)
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataURL(MetaDataParser.java:137)
at org.datanucleus.metadata.MetaDataUtils.parsePersistenceFiles(MetaDataUtils.java:956)
at org.datanucleus.api.jpa.JPAEntityManagerFactory.<init>(JPAEntityManagerFactory.java:342)
at org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
... 6 more
Caused by: org.datanucleus.exceptions.NucleusUserException: MetaData handler plugin "persistence" was not found. Please check your CLASSPATH and plugin specification.
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataStream(MetaDataParser.java:263)
... 11 more
I unziped the jar and the datanucleus-core files are there. I can not figure out what is happening.
You've not bothered looking after MANIFEST.MF and plugin.xml files when you changed the jar(s). DataNucleus jars are packaged to allow the (OSGi-based) plugin mechanism to identify plugins and capabilities. You've disabled that by playing around with those jars, so get the consequences.
Solution : either use the jars as provided, or merge them correctly (in which case it's your responsibility)

Categories

Resources